Skip to content

Commit fc349f0

Browse files
committed
Add server_request_body_incomplete flag to track incomplete body transfers
1 parent 551e64e commit fc349f0

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

include/proxy/http/HttpSM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class HttpSM : public Continuation, public PluginUserArgs<TS_USER_ARGS_TXN>
512512
int server_connection_provided_cert = 0;
513513
int64_t client_request_body_bytes = 0;
514514
int64_t server_request_body_bytes = 0;
515+
bool server_request_body_incomplete = false;
515516
int64_t server_response_body_bytes = 0;
516517
int64_t client_response_body_bytes = 0;
517518
int64_t cache_response_body_bytes = 0;

src/proxy/http/HttpSM.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,11 +2072,14 @@ HttpSM::state_read_server_response_header(int event, void *data)
20722072
if (tunnel.is_tunnel_alive()) {
20732073
// Record bytes already written to the server before aborting the tunnel.
20742074
// tunnel_handler_post_server() won't be called after abort, so we must
2075-
// capture this here to prevent the connection from being pooled later.
2075+
// capture this here for stats/logging purposes.
20762076
HttpTunnelConsumer *server_consumer = tunnel.get_consumer(server_txn);
20772077
if (server_consumer && server_request_body_bytes == 0) {
20782078
server_request_body_bytes = server_consumer->bytes_written;
20792079
}
2080+
// Mark the body transfer as incomplete so the origin connection is not
2081+
// pooled. The origin may have unconsumed body data in the TCP stream.
2082+
server_request_body_incomplete = true;
20802083
tunnel.abort_tunnel();
20812084
// Make sure client connection is closed when we are done in case there is cruft left over
20822085
t_state.client_info.keep_alive = HTTPKeepAlive::NO_KEEPALIVE;
@@ -3183,13 +3186,13 @@ HttpSM::tunnel_handler_server(int event, HttpTunnelProducer *p)
31833186

31843187
bool close_connection = false;
31853188

3186-
// Don't pool the connection if a request body was sent to the origin.
3189+
// Don't pool the connection if the request body transfer was incomplete.
31873190
// The origin may not have consumed all of it before sending this response,
31883191
// leaving unconsumed body data in the TCP stream that would corrupt the
31893192
// next request on this connection.
31903193
if (t_state.current.server->keep_alive == HTTPKeepAlive::KEEPALIVE && server_entry->eos == false &&
31913194
plugin_tunnel_type == HttpPluginTunnel_t::NONE && t_state.txn_conf->keep_alive_enabled_out == 1 &&
3192-
server_request_body_bytes == 0) {
3195+
!server_request_body_incomplete) {
31933196
close_connection = false;
31943197
} else {
31953198
if (t_state.current.server->keep_alive != HTTPKeepAlive::KEEPALIVE) {
@@ -6047,7 +6050,7 @@ HttpSM::release_server_session(bool serve_from_cache)
60476050
(t_state.hdr_info.server_response.status_get() == HTTPStatus::NOT_MODIFIED ||
60486051
(t_state.hdr_info.server_request.method_get_wksidx() == HTTP_WKSIDX_HEAD &&
60496052
t_state.www_auth_content != HttpTransact::CacheAuth_t::NONE)) &&
6050-
plugin_tunnel_type == HttpPluginTunnel_t::NONE && (!server_entry || !server_entry->eos) && server_request_body_bytes == 0) {
6053+
plugin_tunnel_type == HttpPluginTunnel_t::NONE && (!server_entry || !server_entry->eos) && !server_request_body_incomplete) {
60516054
if (t_state.www_auth_content == HttpTransact::CacheAuth_t::NONE || serve_from_cache == false) {
60526055
// Must explicitly set the keep_alive_no_activity time before doing the release
60536056
server_txn->set_inactivity_timeout(HRTIME_SECONDS(t_state.txn_conf->keep_alive_no_activity_timeout_out));

0 commit comments

Comments
 (0)