From f5acbf79e2492d25c034f4dcbd85ac13aa3b519a Mon Sep 17 00:00:00 2001 From: Vignesh Babu Date: Tue, 9 Jan 2024 17:30:44 +0000 Subject: [PATCH] [flakiness] Fix timeout flakiness in //test/core/end2end:cancel_after_invoke_test Based on discussions with drfloob@ PiperOrigin-RevId: 596958525 --- .../ext/transport/chttp2/server/chttp2_server.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.cc b/src/core/ext/transport/chttp2/server/chttp2_server.cc index e5a6282024e..dea28445a4f 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.cc +++ b/src/core/ext/transport/chttp2/server/chttp2_server.cc @@ -617,8 +617,17 @@ void Chttp2ServerListener::ActiveConnection::Start( RefCountedPtr handshaking_state_ref; listener_ = std::move(listener); { - MutexLock lock(&mu_); - if (shutdown_) return; + ReleasableMutexLock lock(&mu_); + if (shutdown_) { + lock.Release(); + // If the Connection is already shutdown at this point, it implies the + // owning Chttp2ServerListener and all associated ActiveConnections have + // been orphaned. The generated endpoints need to be shutdown here to + // ensure the tcp connections are closed appropriately. + grpc_endpoint_shutdown(endpoint, absl::OkStatus()); + grpc_endpoint_destroy(endpoint); + return; + } // Hold a ref to HandshakingState to allow starting the handshake outside // the critical region. handshaking_state_ref = handshaking_state_->Ref();