diff --git a/proxy/ProxySession.cc b/proxy/ProxySession.cc index 40d5b491d23..78935669c63 100644 --- a/proxy/ProxySession.cc +++ b/proxy/ProxySession.cc @@ -334,3 +334,37 @@ ProxySession::has_hooks() const { return this->api_hooks.has_hooks() || http_global_hooks->has_hooks(); } + +void +ProxySession::add_to_active_queue() +{ + UnixNetVConnection *vc = dynamic_cast(this->get_netvc()); + if (vc) { // If it isn't a netvc, no active_queue to manage + if (mutex->thread_holding == this_ethread()) { + // Should be safe to blocking grab the nh mutex, probably already have it + // but will not in the direct schedule case + SCOPED_MUTEX_LOCK(lock, vc->nh->mutex, this_ethread()); + vc->add_to_active_queue(); + } else { + ink_release_assert(!"BUG: Trying to add vc to active_queue from non-owning thread"); + } + } +} + +void +ProxySession::add_to_keep_alive_queue() +{ + UnixNetVConnection *vc = dynamic_cast(this->get_netvc()); + if (vc) { // If it isn't a netvc, no keep_alive_queue to manage + if (vc->active_timeout_in == 0) { + if (vc && mutex->thread_holding == this_ethread()) { + // Should be safe to blocking grab the nh mutex, probably already have it + // but will not in the direct schedule case + SCOPED_MUTEX_LOCK(lock, vc->nh->mutex, this_ethread()); + vc->add_to_keep_alive_queue(); + } else { + ink_release_assert(!"BUG: Trying to add vc to keep_alive_queue from non-owning thread"); + } + } + } +} diff --git a/proxy/ProxySession.h b/proxy/ProxySession.h index 4770683f2bd..07451ac63b5 100644 --- a/proxy/ProxySession.h +++ b/proxy/ProxySession.h @@ -143,6 +143,12 @@ class ProxySession : public VConnection APIHook *hook_get(TSHttpHookID id) const; HttpAPIHooks const *feature_hooks() const; + + // Wrappers to grab appropriate locks and put + // the assocated netvc on the appropriate queue + void add_to_active_queue(); + void add_to_keep_alive_queue(); + //////////////////// // Members diff --git a/proxy/http/Http1ClientSession.cc b/proxy/http/Http1ClientSession.cc index d5b2269ba20..41cc2897c8f 100644 --- a/proxy/http/Http1ClientSession.cc +++ b/proxy/http/Http1ClientSession.cc @@ -435,7 +435,7 @@ Http1ClientSession::release(ProxyTransaction *trans) if (client_vc) { client_vc->cancel_active_timeout(); - client_vc->add_to_keep_alive_queue(); + this->add_to_keep_alive_queue(); } trans->destroy(); } @@ -459,7 +459,7 @@ Http1ClientSession::new_transaction() trans.set_proxy_ssn(this); transact_count++; - client_vc->add_to_active_queue(); + this->add_to_active_queue(); trans.new_transaction(); } diff --git a/proxy/http2/Http2ConnectionState.cc b/proxy/http2/Http2ConnectionState.cc index 7fb41ce6f64..7891638923f 100644 --- a/proxy/http2/Http2ConnectionState.cc +++ b/proxy/http2/Http2ConnectionState.cc @@ -1186,7 +1186,7 @@ Http2ConnectionState::create_stream(Http2StreamId new_id, Http2Error &error) new_stream->mutex = new_ProxyMutex(); new_stream->is_first_transaction_flag = get_stream_requests() == 0; increment_stream_requests(); - ua_session->get_netvc()->add_to_active_queue(); + ua_session->add_to_active_queue(); return new_stream; } @@ -1264,10 +1264,7 @@ Http2ConnectionState::cleanup_streams() if (!is_state_closed()) { SCOPED_MUTEX_LOCK(lock, this->ua_session->mutex, this_ethread()); - UnixNetVConnection *vc = static_cast(ua_session->get_netvc()); - if (vc && vc->active_timeout_in == 0) { - vc->add_to_keep_alive_queue(); - } + ua_session->add_to_keep_alive_queue(); } } @@ -1353,11 +1350,8 @@ Http2ConnectionState::release_stream(Http2Stream *stream) // If the number of clients is 0, HTTP2_SESSION_EVENT_FINI is not received or sent, and ua_session is active, // then mark the connection as inactive ua_session->clear_session_active(); - UnixNetVConnection *vc = static_cast(ua_session->get_netvc()); - if (vc && vc->active_timeout_in == 0) { - // With heavy traffic, ua_session could be destroyed. Do not touch ua_session after this. - vc->add_to_keep_alive_queue(); - } + // With heavy traffic, ua_session could be destroyed. Do not touch ua_session after this. + ua_session->add_to_keep_alive_queue(); } else { schedule_zombie_event(); }