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();