From 46c81cb7c7c18d52c77d0633ffa765b7721bd241 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Fri, 2 Apr 2021 07:56:13 +0900 Subject: [PATCH 1/2] Do NOT kill tunnel if it has any consumer besides HT_HTTP_CLIENT (#7641) (cherry picked from commit 270ca6e84eba758e44c9b2a15046eaa7b8af8d8a) --- proxy/http/HttpSM.cc | 4 ++-- proxy/http/HttpTunnel.h | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index e43fd32aac3..f2227148759 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -839,9 +839,9 @@ HttpSM::state_watch_for_client_abort(int event, void *data) * client. */ case VC_EVENT_EOS: { - // We got an early EOS. + // We got an early EOS. If the tunnal has cache writer, don't kill it for background fill. NetVConnection *netvc = ua_txn->get_netvc(); - if (ua_txn->allow_half_open()) { + if (ua_txn->allow_half_open() || tunnel.has_consumer_besides_client()) { if (netvc) { netvc->do_io_shutdown(IO_SHUTDOWN_READ); } diff --git a/proxy/http/HttpTunnel.h b/proxy/http/HttpTunnel.h index a432f3f5ee1..34186ddb283 100644 --- a/proxy/http/HttpTunnel.h +++ b/proxy/http/HttpTunnel.h @@ -282,6 +282,7 @@ class HttpTunnel : public Continuation } bool is_tunnel_alive() const; bool has_cache_writer() const; + bool has_consumer_besides_client() const; HttpTunnelProducer *add_producer(VConnection *vc, int64_t nbytes, IOBufferReader *reader_start, HttpProducerHandler sm_handler, HttpTunnelType_t vc_type, const char *name); @@ -514,6 +515,31 @@ HttpTunnel::has_cache_writer() const return false; } +/** + Return false if there is only a consumer for client + */ +inline bool +HttpTunnel::has_consumer_besides_client() const +{ + bool res = true; + + for (const auto &consumer : consumers) { + if (!consumer.alive) { + continue; + } + + if (consumer.vc_type == HT_HTTP_CLIENT) { + res = false; + continue; + } else { + res = true; + break; + } + } + + return res; +} + inline bool HttpTunnelConsumer::is_downstream_from(VConnection *vc) { From cbd67d111c87ae6f85328b35c4f258520e0df9c4 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Tue, 6 Apr 2021 08:41:12 -0500 Subject: [PATCH 2/2] Fix has_consumer_besides_client to deal with no clients (#7685) (cherry picked from commit 09e72839258a4f748aace4908c996e843e6d5176) --- proxy/http/HttpTunnel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/http/HttpTunnel.h b/proxy/http/HttpTunnel.h index 34186ddb283..9cc515530fe 100644 --- a/proxy/http/HttpTunnel.h +++ b/proxy/http/HttpTunnel.h @@ -521,7 +521,7 @@ HttpTunnel::has_cache_writer() const inline bool HttpTunnel::has_consumer_besides_client() const { - bool res = true; + bool res = false; // case of no consumers for (const auto &consumer : consumers) { if (!consumer.alive) {