diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index ff1aafe01da..efee17ef47a 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -36,8 +36,9 @@ #include "tscpp/util/PostScript.h" #include "tscpp/util/LocalBuffer.h" -#include +#include #include +#include #define REMEMBER(e, r) \ { \ @@ -1197,6 +1198,9 @@ Http2ConnectionState::destroy() if (zombie_event) { zombie_event->cancel(); } + for (auto *event : _xmit_events) { + event->cancel(); + } // release the mutex after the events are cancelled and sessions are destroyed. mutex = nullptr; // magic happens - assigning to nullptr frees the ProxyMutex } @@ -1280,6 +1284,10 @@ Http2ConnectionState::main_event_handler(int event, void *edata) } else if (edata == fini_event) { fini_event = nullptr; } + if (auto const xmit_event = std::find(_xmit_events.begin(), _xmit_events.end(), static_cast(edata)); + xmit_event != _xmit_events.end()) { + _xmit_events.erase(xmit_event); + } ++recursion; switch (event) { // Finalize HTTP/2 Connection @@ -1383,6 +1391,10 @@ Http2ConnectionState::state_closed(int event, void *edata) } else if (edata == shutdown_cont_event) { shutdown_cont_event = nullptr; } + if (auto const xmit_event = std::find(_xmit_events.begin(), _xmit_events.end(), static_cast(edata)); + xmit_event != _xmit_events.end()) { + _xmit_events.erase(xmit_event); + } return 0; } @@ -1702,7 +1714,7 @@ Http2ConnectionState::schedule_stream(Http2Stream *stream) _scheduled = true; SET_HANDLER(&Http2ConnectionState::main_event_handler); - this_ethread()->schedule_imm_local((Continuation *)this, HTTP2_SESSION_EVENT_XMIT); + _xmit_events.push_back(this_ethread()->schedule_imm_local((Continuation *)this, HTTP2_SESSION_EVENT_XMIT)); } } @@ -1747,7 +1759,7 @@ Http2ConnectionState::send_data_frames_depends_on_priority() break; } - this_ethread()->schedule_imm_local((Continuation *)this, HTTP2_SESSION_EVENT_XMIT); + _xmit_events.push_back(this_ethread()->schedule_imm_local((Continuation *)this, HTTP2_SESSION_EVENT_XMIT)); return; } diff --git a/proxy/http2/Http2ConnectionState.h b/proxy/http2/Http2ConnectionState.h index fff7763f2a1..0cd88d46088 100644 --- a/proxy/http2/Http2ConnectionState.h +++ b/proxy/http2/Http2ConnectionState.h @@ -24,6 +24,7 @@ #pragma once #include +#include #include "NetTimeout.h" @@ -242,6 +243,7 @@ class Http2ConnectionState : public Continuation Event *shutdown_cont_event = nullptr; Event *fini_event = nullptr; Event *zombie_event = nullptr; + std::vector _xmit_events; }; ///////////////////////////////////////////////