From 44bd0528c769ae5e469c3f013b0b4d3e59f57718 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Oct 2024 16:04:33 -0700 Subject: [PATCH] [chaotic-good] Don't add new streams after transport closed (#37887) Prior to this change events could conspire such that newly read streams got added after the AbortWithError() code ran, and so those calls would be orphaned in the transport forever - continuing to hold a ref. Closes #37887 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37887 from ctiller:flake-fightas-20 2648d7f37f5b10a6b8501b1b0fb02ee1d5a28fac PiperOrigin-RevId: 684609806 --- src/core/ext/transport/chaotic_good/server_transport.cc | 4 ++++ src/core/ext/transport/chaotic_good/server_transport.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/core/ext/transport/chaotic_good/server_transport.cc b/src/core/ext/transport/chaotic_good/server_transport.cc index b166d79380f..b28f99cda92 100644 --- a/src/core/ext/transport/chaotic_good/server_transport.cc +++ b/src/core/ext/transport/chaotic_good/server_transport.cc @@ -397,6 +397,7 @@ void ChaoticGoodServerTransport::AbortWithError() { // Close all the available pipes. outgoing_frames_.MarkClosed(); ReleasableMutexLock lock(&mu_); + aborted_with_error_ = true; StreamMap stream_map = std::move(stream_map_); stream_map_.clear(); state_tracker_.SetState(GRPC_CHANNEL_SHUTDOWN, @@ -439,6 +440,9 @@ absl::Status ChaoticGoodServerTransport::NewStream( GRPC_TRACE_LOG(chaotic_good, INFO) << "CHAOTIC_GOOD " << this << " NewStream " << stream_id; MutexLock lock(&mu_); + if (aborted_with_error_) { + return absl::UnavailableError("Transport closed"); + } auto it = stream_map_.find(stream_id); if (it != stream_map_.end()) { return absl::InternalError("Stream already exists"); diff --git a/src/core/ext/transport/chaotic_good/server_transport.h b/src/core/ext/transport/chaotic_good/server_transport.h index 49fd5ae015f..9148e5dca8b 100644 --- a/src/core/ext/transport/chaotic_good/server_transport.h +++ b/src/core/ext/transport/chaotic_good/server_transport.h @@ -143,6 +143,7 @@ class ChaoticGoodServerTransport final : public ServerTransport { Mutex mu_; // Map of stream incoming server frames, key is stream_id. StreamMap stream_map_ ABSL_GUARDED_BY(mu_); + bool aborted_with_error_ ABSL_GUARDED_BY(mu_) = false; uint32_t last_seen_new_stream_id_ = 0; RefCountedPtr party_; ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(mu_){