diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index 23eff855b44..40a08341496 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -123,9 +123,7 @@ Http2Stream::main_event_handler(int event, void *edata) } reentrancy_count--; // Clean stream up if the terminate flag is set and we are at the bottom of the handler stack - if (terminate_stream && reentrancy_count == 0) { - destroy(); - } + terminate_if_possible(); return 0; } @@ -359,9 +357,18 @@ Http2Stream::transaction_done() ink_assert(cross_thread_event == nullptr); // Schedule the destroy to occur after we unwind here. IF we call directly, may delete with reference on the stack. terminate_stream = true; - if (terminate_stream && reentrancy_count == 0) { - destroy(); - } + terminate_if_possible(); + } +} + +void +Http2Stream::terminate_if_possible() +{ + if (terminate_stream && reentrancy_count == 0) { + Http2ClientSession *h2_parent = static_cast(parent); + SCOPED_MUTEX_LOCK(lock, h2_parent->connection_state.mutex, this_ethread()); + h2_parent->connection_state.delete_stream(this); + destroy(); } } diff --git a/proxy/http2/Http2Stream.h b/proxy/http2/Http2Stream.h index fbdef7ad0b4..7c1840b08e9 100644 --- a/proxy/http2/Http2Stream.h +++ b/proxy/http2/Http2Stream.h @@ -147,6 +147,7 @@ class Http2Stream : public ProxyClientTransaction VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *abuffer, bool owner = false) override; void do_io_close(int lerrno = -1) override; void initiating_close(); + void terminate_if_possible(); void do_io_shutdown(ShutdownHowTo_t) override {} void update_read_request(int64_t read_len, bool send_update); bool update_write_request(IOBufferReader *buf_reader, int64_t write_len, bool send_update);