fix deadlock

pull/33499/head
Vignesh Babu 2 years ago
parent 3def471f96
commit c9a1bdc3dc
  1. 17
      src/core/lib/event_engine/posix_engine/posix_endpoint.cc

@ -570,26 +570,21 @@ bool PosixEndpointImpl::HandleReadLocked(absl::Status& status) {
} }
void PosixEndpointImpl::HandleRead(absl::Status status) { void PosixEndpointImpl::HandleRead(absl::Status status) {
read_mu_.Lock();
bool ret = false; bool ret = false;
absl::AnyInvocable<void(absl::Status)> cb = nullptr;
grpc_core::EnsureRunInExecCtx([&, this]() mutable { grpc_core::EnsureRunInExecCtx([&, this]() mutable {
read_mu_.AssertHeld(); grpc_core::MutexLock lock(&read_mu_);
ret = HandleReadLocked(status); ret = HandleReadLocked(status);
if (!ret) { if (ret) {
// The lock needs to be released before ExecCtx Flush because the flush cb = std::move(read_cb_);
// may trigger execution of the reclaimer which may try to acquire the read_cb_ = nullptr;
// same lock again causing a deadlock. incoming_buffer_ = nullptr;
read_mu_.Unlock();
} }
}); });
if (!ret) { if (!ret) {
handle_->NotifyOnRead(on_read_); handle_->NotifyOnRead(on_read_);
return; return;
} }
absl::AnyInvocable<void(absl::Status)> cb = std::move(read_cb_);
read_cb_ = nullptr;
incoming_buffer_ = nullptr;
read_mu_.Unlock();
cb(status); cb(status);
Unref(); Unref();
} }

Loading…
Cancel
Save