diff --git a/connections/implementation/base_endpoint_channel.cc b/connections/implementation/base_endpoint_channel.cc index d9b98916..d404d7aa 100644 --- a/connections/implementation/base_endpoint_channel.cc +++ b/connections/implementation/base_endpoint_channel.cc @@ -265,6 +265,11 @@ void BaseEndpointChannel::Close() { { // In case channel is paused, resume it first thing. MutexLock lock(&is_paused_mutex_); + if (is_closed_) { + NEARBY_LOGS(VERBOSE) << "EndpointChannel already closed"; + return; + } + is_closed_ = true; UnblockPausedWriter(); } CloseIo(); diff --git a/connections/implementation/base_endpoint_channel.h b/connections/implementation/base_endpoint_channel.h index e3d77f65..5259748c 100644 --- a/connections/implementation/base_endpoint_channel.h +++ b/connections/implementation/base_endpoint_channel.h @@ -130,6 +130,7 @@ class BaseEndpointChannel : public EndpointChannel { ConditionVariable is_paused_cond_{&is_paused_mutex_}; // If true, writes should block until this has been set to false. bool is_paused_ ABSL_GUARDED_BY(is_paused_mutex_) = false; + bool is_closed_ ABSL_GUARDED_BY(is_paused_mutex_) = false; // The medium technology information of this endpoint channel. location::nearby::proto::connections::ConnectionTechnology technology_;