From fbff32673fbfab20b8af732ad16226cac98e6ebd Mon Sep 17 00:00:00 2001 From: Lu Qiuwen Date: Thu, 22 Nov 2018 13:47:17 +0800 Subject: [PATCH] =?UTF-8?q?Close=20#76=20=E4=BF=AE=E6=AD=A3HTTP=20Upgrade?= =?UTF-8?q?=E5=90=8E=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AEDetach=E8=AF=A5?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E7=9A=84=E9=97=AE=E9=A2=98=20*=20=E5=8E=9F?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E5=A4=84?= =?UTF-8?q?=E7=90=86Upgrade=E6=A0=87=E5=BF=97=E4=BD=8D=EF=BC=8C=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=BF=9E=E6=8E=A5=E5=86=8D=E6=AC=A1=E8=BF=9B=E5=85=A5?= =?UTF-8?q?HTTP=E8=A7=A3=E6=9E=90=E6=B5=81=E7=A8=8B=E4=BB=8E=E8=80=8C?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A3=E6=9E=90=EF=BC=8C=E6=8A=A5#76?= =?UTF-8?q?=E6=89=80=E5=88=97=E4=B9=8B=E9=97=AE=E9=A2=98=E3=80=82=20*=20?= =?UTF-8?q?=E7=8E=B0=E4=BF=AE=E6=AD=A3=EF=BC=8C=E4=BA=A6=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?#76=E6=89=80=E7=A4=BA=E6=97=A5=E5=BF=97=E4=B9=8B=E4=BA=94?= =?UTF-8?q?=E5=85=83=E7=BB=84=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/tcp_stream.cpp | 30 +++++++++++++++---------- plugin/protocol/http/src/http_entry.cpp | 17 +++++++------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/platform/src/tcp_stream.cpp b/platform/src/tcp_stream.cpp index 3e9e170..450c2bd 100644 --- a/platform/src/tcp_stream.cpp +++ b/platform/src/tcp_stream.cpp @@ -208,11 +208,11 @@ struct tfe_stream_write_ctx * tfe_stream_write_frag_start(const struct tfe_strea int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned char * data, size_t size) { - if(w_ctx->_stream == NULL) - { + if (w_ctx->_stream == NULL) + { return -EPIPE; } - + struct tfe_conn_private * this_conn = __this_conn(w_ctx->_stream, w_ctx->dir); int ret = 0; if (this_conn != NULL) @@ -254,7 +254,7 @@ void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx) w_ctx->_stream->w_ctx_upstream = NULL; } -__out: +__out: free(w_ctx); } @@ -503,6 +503,11 @@ static void __stream_bev_readcb(struct bufferevent * bev, void * arg) plug_ctx->is_plugin_opened = 1; } + if (plug_ctx->state == PLUG_STATE_DETACHED) + { + continue; + } + if (p_info_iter->on_data != NULL) { action_tmp = p_info_iter->on_data(&_stream->head, _stream->thread_ref->thread_id, @@ -677,11 +682,11 @@ __close_connection: if (*ref_this_conn != NULL) { /* There is a frag writter setted, need to clear the reference of stream in the writter to indicate the connection is closed */ - if(*ref_this_write_ctx != NULL) + if (*ref_this_write_ctx != NULL) { (*ref_this_write_ctx)->_stream = NULL; } - + __conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream); *ref_this_conn = NULL; *ref_this_ssl_stream = NULL; @@ -972,15 +977,15 @@ int __fd_ttl_option_setup(struct tfe_stream_private * _stream, evutil_socket_t f struct sockaddr_storage sk_storage; socklen_t sk_storage_len = sizeof(sk_storage); - if (getsockname(fd, (struct sockaddr *)&sk_storage, &sk_storage_len) < 0) + if (getsockname(fd, (struct sockaddr *) &sk_storage, &sk_storage_len) < 0) { TFE_STREAM_LOG_ERROR(_stream, "getsockname(fd = %d) failed: %s", fd, strerror(errno)); return -1; } /* For IPv4, set TTL */ - unsigned int __ttl = (unsigned int)ttl; - const char * __str_family = NULL; + unsigned int __ttl = (unsigned int) ttl; + const char * __str_family = NULL; int ret = 0; if (sk_storage.ss_family == AF_INET) @@ -995,10 +1000,11 @@ int __fd_ttl_option_setup(struct tfe_stream_private * _stream, evutil_socket_t f } else { assert(0); } - if(ret < 0) + if (ret < 0) { TFE_STREAM_LOG_ERROR(_stream, "setsockopt(ttl = %u, fd = %d, family = %s) failed: %s", - __ttl, fd, __str_family, strerror(errno)); return -2; + __ttl, fd, __str_family, strerror(errno)); + return -2; } return 0; @@ -1080,7 +1086,7 @@ void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket } int __ttl = (dir == CONN_DIR_UPSTREAM) ? tcp_options->tcp_ttl_upstream : tcp_options->tcp_ttl_downstream; - if(__ttl > 0 && __fd_ttl_option_setup(_stream, fd, __ttl) < 0) + if (__ttl > 0 && __fd_ttl_option_setup(_stream, fd, __ttl) < 0) { TFE_STREAM_LOG_ERROR(stream, "Failed at setup FD's ttl option, ttl = %d, fd = %d", __ttl, fd); } diff --git a/plugin/protocol/http/src/http_entry.cpp b/plugin/protocol/http/src/http_entry.cpp index e29e6b4..eaf20dd 100644 --- a/plugin/protocol/http/src/http_entry.cpp +++ b/plugin/protocol/http/src/http_entry.cpp @@ -89,7 +89,7 @@ int http_plugin_init(struct tfe_proxy * proxy) plugin_ctx->gc_event_hs_private[thread_id] = gc_event; } - plugin_ctx->access_logger = MESA_create_runtime_log_handle("log/http-access.log", RLOG_LV_INFO); + plugin_ctx->access_logger = MESA_create_runtime_log_handle("log/http.log", RLOG_LV_INFO); assert(plugin_ctx->access_logger != NULL); return 0; @@ -419,6 +419,11 @@ enum tfe_stream_action http_connection_entry(const struct tfe_stream * stream, e return ACTION_DEFER_DATA; } + if (hf_private_in->is_upgrade || hf_private_in->is_passthrough) + { + goto __passthrough; + } + /* Need more data, no boundary touched */ if (ret == 0) { @@ -431,18 +436,14 @@ enum tfe_stream_action http_connection_entry(const struct tfe_stream * stream, e return hf_private_in->stream_action; } - if (ret == -1 && hf_private_in->is_passthrough) - { - goto __passthrough; - } - /* Some kind of error happened, write log and detach the stream */ if (ret == -1) { - TFE_STREAM_LOG_ERROR(stream, "Failed at parsing stream as HTTP: %u, %s, %s", - hf_private_in->parse_errno, http_errno_name(hf_private_in->parse_errno), + TFE_LOG_ERROR(g_http_plugin->access_logger, "%s: Failed at parsing stream as HTTP, %u, %s, %s", + stream->str_stream_info, hf_private_in->parse_errno, http_errno_name(hf_private_in->parse_errno), http_errno_description(hf_private_in->parse_errno)); + tfe_hexdump2file(stderr, "Failed at parsing stream as HTTP", data, (unsigned int)len); goto __passthrough; }