diff --git a/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.cc b/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.cc index d5723e82d4a..be3dfa83f53 100644 --- a/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.cc +++ b/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.cc @@ -134,9 +134,12 @@ auto ChaoticGoodConnector::WaitForDataEndpointSetup( endpoint) mutable { ExecCtx exec_ctx; if (!endpoint.ok() || self->handshake_mgr_ == nullptr) { - ExecCtx::Run(DEBUG_LOCATION, - std::exchange(self->notify_, nullptr), - GRPC_ERROR_CREATE("connect endpoint failed")); + MutexLock lock(&self->mu_); + if (self->notify_ != nullptr) { + ExecCtx::Run(DEBUG_LOCATION, + std::exchange(self->notify_, nullptr), + GRPC_ERROR_CREATE("connect endpoint failed")); + } return; } auto* chaotic_good_ext = @@ -240,9 +243,9 @@ void ChaoticGoodConnector::Connect(const Args& args, Result* result, GRPC_ERROR_CREATE("connector shutdown")); return; } + notify_ = notify; } args_ = args; - notify_ = notify; resolved_addr_ = EventEngine::ResolvedAddress( reinterpret_cast(args_.address->addr), args_.address->len); @@ -253,11 +256,14 @@ void ChaoticGoodConnector::Connect(const Args& args, Result* result, endpoint) mutable { ExecCtx exec_ctx; if (!endpoint.ok() || self->handshake_mgr_ == nullptr) { - auto endpoint_status = endpoint.status(); - auto error = GRPC_ERROR_CREATE_REFERENCING("connect endpoint failed", - &endpoint_status, 1); - ExecCtx::Run(DEBUG_LOCATION, std::exchange(self->notify_, nullptr), - error); + MutexLock lock(&self->mu_); + if (self->notify_ != nullptr) { + auto endpoint_status = endpoint.status(); + auto error = GRPC_ERROR_CREATE_REFERENCING( + "connect endpoint failed", &endpoint_status, 1); + ExecCtx::Run(DEBUG_LOCATION, std::exchange(self->notify_, nullptr), + error); + } return; } auto* chaotic_good_ext = @@ -320,8 +326,8 @@ void ChaoticGoodConnector::OnHandshakeDone( [self = RefAsSubclass()](absl::Status status) { GRPC_TRACE_LOG(chaotic_good, INFO) << "ChaoticGoodConnector::OnHandshakeDone: " << status; + MutexLock lock(&self->mu_); if (status.ok()) { - MutexLock lock(&self->mu_); self->result_->transport = new ChaoticGoodClientTransport( std::move(self->control_endpoint_), std::move(self->data_endpoint_), self->args_.channel_args, diff --git a/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.h b/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.h index d981689f72b..5078d384369 100644 --- a/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.h +++ b/src/core/ext/transport/chaotic_good/client/chaotic_good_connector.h @@ -83,7 +83,7 @@ class ChaoticGoodConnector : public SubchannelConnector { Mutex mu_; Args args_; Result* result_ ABSL_GUARDED_BY(mu_); - grpc_closure* notify_ = nullptr; + grpc_closure* notify_ ABSL_GUARDED_BY(mu_) = nullptr; bool is_shutdown_ ABSL_GUARDED_BY(mu_) = false; absl::StatusOr resolved_addr_;