diff --git a/proxy/ProxyTransaction.cc b/proxy/ProxyTransaction.cc index 9be892ff999..214c710c5ec 100644 --- a/proxy/ProxyTransaction.cc +++ b/proxy/ProxyTransaction.cc @@ -32,7 +32,7 @@ ProxyTransaction::ProxyTransaction() : VConnection(nullptr) {} void ProxyTransaction::new_transaction(bool from_early_data) { - ink_assert(_sm == nullptr); + ink_release_assert(_sm == nullptr); // Defensive programming, make sure nothing persists across // connection re-use @@ -56,20 +56,6 @@ ProxyTransaction::new_transaction(bool from_early_data) _sm->attach_client_session(this, _reader); } -void -ProxyTransaction::release(IOBufferReader *r) -{ - HttpTxnDebug("[%" PRId64 "] session released by sm [%" PRId64 "]", _proxy_ssn ? _proxy_ssn->connection_id() : 0, - _sm ? _sm->sm_id : 0); - - this->decrement_client_transactions_stat(); - - // Pass along the release to the session - if (_proxy_ssn) { - _proxy_ssn->release(this); - } -} - void ProxyTransaction::attach_server_session(Http1ServerSession *ssession, bool transaction_done) { @@ -197,3 +183,10 @@ ProxyTransaction::get_transaction_priority_dependence() const { return 0; } + +void +ProxyTransaction::transaction_done() +{ + SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); + this->decrement_client_transactions_stat(); +} diff --git a/proxy/ProxyTransaction.h b/proxy/ProxyTransaction.h index 83a2111610c..5ae71c84656 100644 --- a/proxy/ProxyTransaction.h +++ b/proxy/ProxyTransaction.h @@ -40,8 +40,8 @@ class ProxyTransaction : public VConnection virtual void new_transaction(bool from_early_data = false); virtual void attach_server_session(Http1ServerSession *ssession, bool transaction_done = true); Action *adjust_thread(Continuation *cont, int event, void *data); - virtual void release(IOBufferReader *r); - virtual void transaction_done() = 0; + virtual void release(IOBufferReader *r) = 0; + virtual void transaction_done(); virtual void destroy(); /// Virtual Accessors diff --git a/proxy/http/Http1ClientSession.cc b/proxy/http/Http1ClientSession.cc index 9177c0e4da3..7d68b248bf9 100644 --- a/proxy/http/Http1ClientSession.cc +++ b/proxy/http/Http1ClientSession.cc @@ -395,8 +395,19 @@ Http1ClientSession::release(ProxyTransaction *trans) { ink_assert(read_state == HCS_ACTIVE_READER || read_state == HCS_INIT); - // Timeout events should be delivered to the session - this->do_io_write(this, 0, nullptr); + // When release is called from start() to read the first transaction, get_sm() + // will return null. + HttpSM *sm = trans->get_sm(); + if (sm) { + MgmtInt ka_in = trans->get_sm()->t_state.txn_conf->keep_alive_no_activity_timeout_in; + set_inactivity_timeout(HRTIME_SECONDS(ka_in)); + + this->clear_session_active(); + this->ssn_last_txn_time = Thread::get_hrtime(); + + // Timeout events should be delivered to the session + this->do_io_write(this, 0, nullptr); + } // Check to see there is remaining data in the // buffer. If there is, spin up a new state diff --git a/proxy/http/Http1Transaction.cc b/proxy/http/Http1Transaction.cc index d2f8b2c3ad0..29ebec0da99 100644 --- a/proxy/http/Http1Transaction.cc +++ b/proxy/http/Http1Transaction.cc @@ -28,22 +28,6 @@ void Http1Transaction::release(IOBufferReader *r) { - // Must set this inactivity count here rather than in the session because the state machine - // is not available then - MgmtInt ka_in = _sm->t_state.txn_conf->keep_alive_no_activity_timeout_in; - set_inactivity_timeout(HRTIME_SECONDS(ka_in)); - - _proxy_ssn->clear_session_active(); - _proxy_ssn->ssn_last_txn_time = Thread::get_hrtime(); - - // Make sure that the state machine is returning - // correct buffer reader - ink_assert(r == _reader); - if (r != _reader) { - this->do_io_close(); - } else { - super_type::release(r); - } } void @@ -55,6 +39,8 @@ Http1Transaction::destroy() // todo make ~Http1Transaction() void Http1Transaction::transaction_done() { + SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); + super_type::transaction_done(); if (_proxy_ssn) { static_cast(_proxy_ssn)->release_transaction(); } diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index 611e2732be7..1065970d680 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -3368,6 +3368,7 @@ HttpSM::tunnel_handler_ua(int event, HttpTunnelConsumer *c) } else { ink_assert(ua_buffer_reader != nullptr); ua_txn->release(ua_buffer_reader); + ua_txn->get_proxy_ssn()->release(ua_txn); ua_buffer_reader = nullptr; // ua_txn = NULL; } diff --git a/proxy/http2/Http2Stream.cc b/proxy/http2/Http2Stream.cc index 417a6d6f325..acb955a849b 100644 --- a/proxy/http2/Http2Stream.cc +++ b/proxy/http2/Http2Stream.cc @@ -49,6 +49,7 @@ Http2Stream::init(Http2StreamId sid, ssize_t initial_rwnd) { this->mark_milestone(Http2StreamMilestone::OPEN); + this->_sm = nullptr; this->_id = sid; this->_thread = this_ethread(); this->_client_rwnd = initial_rwnd; @@ -346,7 +347,6 @@ void Http2Stream::do_io_close(int /* flags */) { SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); - super::release(nullptr); if (!closed) { REMEMBER(NO_EVENT, this->reentrancy_count); @@ -379,6 +379,7 @@ void Http2Stream::transaction_done() { SCOPED_MUTEX_LOCK(lock, this->mutex, this_ethread()); + super::transaction_done(); if (cross_thread_event) { cross_thread_event->cancel(); cross_thread_event = nullptr; @@ -894,10 +895,10 @@ Http2Stream::clear_io_events() } } +// release and do_io_close are the same for the HTTP/2 protocol void Http2Stream::release(IOBufferReader *r) { - super::release(r); this->do_io_close(); } diff --git a/proxy/http3/Http3Transaction.cc b/proxy/http3/Http3Transaction.cc index 6ffb895e11b..ccb43a68cc6 100644 --- a/proxy/http3/Http3Transaction.cc +++ b/proxy/http3/Http3Transaction.cc @@ -108,7 +108,6 @@ HQTransaction::cancel_inactivity_timeout() void HQTransaction::release(IOBufferReader *r) { - super::release(r); this->do_io_close(); this->_sm = nullptr; } @@ -228,6 +227,7 @@ void HQTransaction::transaction_done() { // TODO: start closing transaction + super::transaction_done(); return; }