From aa4629ca3175f7a5bacef9d3aea35105f2a24945 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Thu, 18 Oct 2018 16:20:22 +0800 Subject: [PATCH] =?UTF-8?q?todo:http=20=E5=86=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/tcp_stream.cpp | 11 ++++++-- .../business/pangu-http/src/pangu_logger.cpp | 2 +- plugin/protocol/http/src/http_entry.cpp | 3 ++- plugin/protocol/http/src/http_half.cpp | 25 +++++++++++++------ 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/platform/src/tcp_stream.cpp b/platform/src/tcp_stream.cpp index b115476..bf86feb 100644 --- a/platform/src/tcp_stream.cpp +++ b/platform/src/tcp_stream.cpp @@ -500,7 +500,7 @@ static void __stream_bev_writecb(struct bufferevent * bev, void * arg) struct evbuffer * __output_buffer = bufferevent_get_output(bev); assert(__output_buffer != NULL); - if (*ref_peer_conn == NULL && evbuffer_get_length(__output_buffer) == 0) + if (*ref_peer_conn == NULL && (*ref_this_conn)->on_writing == 0 && evbuffer_get_length(__output_buffer) == 0) { __conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream); *ref_this_conn = NULL; @@ -529,12 +529,14 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void * struct ssl_stream ** ref_this_ssl_stream{}; struct ssl_stream ** ref_peer_ssl_stream{}; + const char * __str_dir = NULL; if (__bev_dir(_stream, bev) == CONN_DIR_UPSTREAM) { ref_this_conn = &_stream->conn_upstream; ref_peer_conn = &_stream->conn_downstream; ref_this_ssl_stream = &_stream->ssl_upstream; ref_peer_ssl_stream = &_stream->ssl_downstream; + __str_dir = "up"; } if (__bev_dir(_stream, bev) == CONN_DIR_DOWNSTREAM) @@ -543,6 +545,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void * ref_peer_conn = &_stream->conn_upstream; ref_this_ssl_stream = &_stream->ssl_downstream; ref_peer_ssl_stream = &_stream->ssl_upstream; + __str_dir = "down"; } if (events & BEV_EVENT_ERROR || events & BEV_EVENT_EOF) @@ -552,6 +555,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void * __stream_bev_readcb(bev, arg); } + fprintf(stderr, "---- eventcb ----, stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir); goto __close_connection; } @@ -563,7 +567,7 @@ __close_connection: struct bufferevent * __peer_bev = (*ref_peer_conn)->bev; struct evbuffer * __peer_output_buffer = bufferevent_get_output(__peer_bev); - if (evbuffer_get_length(__peer_output_buffer) == 0) + if (evbuffer_get_length(__peer_output_buffer) == 0 && (*ref_peer_conn)->on_writing == 0) { __conn_private_destory_with_ssl(ev_base, *ref_peer_conn, *ref_peer_ssl_stream); *ref_peer_conn = NULL; @@ -573,6 +577,9 @@ __close_connection: if (*ref_this_conn != NULL) { + fprintf(stderr, "---- eventcb ----, close this connection, stream = %p, event = %x, dir = %s\n", _stream, events, __str_dir); + + assert((*ref_this_conn)->on_writing == 0); __conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream); *ref_this_conn = NULL; *ref_this_ssl_stream = NULL; diff --git a/plugin/business/pangu-http/src/pangu_logger.cpp b/plugin/business/pangu-http/src/pangu_logger.cpp index 9053a59..1bb753f 100644 --- a/plugin/business/pangu-http/src/pangu_logger.cpp +++ b/plugin/business/pangu-http/src/pangu_logger.cpp @@ -207,7 +207,7 @@ int pangu_send_log(struct pangu_logger* handle, const struct pangu_log* log_msg) cJSON_AddStringToObject(common_obj,req_fields[i].log_filed_name, tmp_val); } } - for(size_t i=0;iresp!=NULL;i++) { tmp_val=tfe_http_std_field_read(http->resp, resp_fields[i].field_id); if(tmp_val!=NULL) diff --git a/plugin/protocol/http/src/http_entry.cpp b/plugin/protocol/http/src/http_entry.cpp index 28007c2..8d1e315 100644 --- a/plugin/protocol/http/src/http_entry.cpp +++ b/plugin/protocol/http/src/http_entry.cpp @@ -171,7 +171,8 @@ int __on_request_handle_user_req_or_resp(const tfe_stream * stream, struct http_ TAILQ_INSERT_TAIL(&hc_private->hs_private_orphan_list, hs_private, next); } - assert(hf_private_req_in->stream_action == ACTION_DEFER_DATA); + assert(hf_private_req_in->stream_action == ACTION_DEFER_DATA + || hf_private_req_in->stream_action == ACTION_DROP_DATA); hf_private_req_in->stream_action = ACTION_DROP_DATA; } diff --git a/plugin/protocol/http/src/http_half.cpp b/plugin/protocol/http/src/http_half.cpp index a3f0c75..8ec8710 100644 --- a/plugin/protocol/http/src/http_half.cpp +++ b/plugin/protocol/http/src/http_half.cpp @@ -838,19 +838,30 @@ void hs_ops_response_set(struct tfe_http_session * session, struct tfe_http_half { struct http_half_private * hf_private = to_hf_private(resp); struct http_session_private * hs_private = to_hs_private(session); - struct http_half_private * hf_in_private = to_hf_response_private(hs_private); + struct http_half_private * hf_in_req_private = to_hf_request_private(hs_private); + struct http_half_private * hf_in_resp_private = to_hf_response_private(hs_private); - if (hf_in_private != NULL) + /* Call at request's callback, early response */ + if(hf_in_req_private != NULL && hf_in_resp_private == NULL) { - if (hf_in_private->stream_action == ACTION_DEFER_DATA) + /* Drop the incoming request */ + if (hf_in_req_private->stream_action == ACTION_DEFER_DATA) { - hf_in_private->user_stream_action = ACTION_DROP_DATA; - hf_in_private->is_user_stream_action_set = true; + hf_in_req_private->user_stream_action = ACTION_DROP_DATA; + hf_in_req_private->is_user_stream_action_set = true; } - else + else assert(0); + } + + /* Call at response's callback, replace incoming response */ + if (hf_in_req_private != NULL && hf_in_resp_private != NULL) + { + if (hf_in_resp_private->stream_action == ACTION_DEFER_DATA) { - assert(0); + hf_in_resp_private->user_stream_action = ACTION_DROP_DATA; + hf_in_resp_private->is_user_stream_action_set = true; } + else assert(0); } assert(hs_private->hf_private_resp_user == NULL);