[party] Race fix (#37726)

Party contains a state field that contains ref count *and some other things*... so RefIfNonZero needs to pay attention to only consider the ref count portion.

Closes #37726

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37726 from ctiller:flake-fightas-7 f2b3b3ff6d
PiperOrigin-RevId: 674514201
pull/37728/head
Craig Tiller 5 months ago committed by Copybara-Service
parent a915689850
commit 536bbbf181
  1. 2
      src/core/ext/transport/chaotic_good/server_transport.cc
  2. 8
      src/core/lib/promise/party.cc

@ -240,7 +240,7 @@ auto ChaoticGoodServerTransport::DeserializeAndPushFragmentToNewCall(
call_initiator->SpawnGuarded(
"server-write", [this, stream_id = frame_header.stream_id,
call_initiator = *call_initiator,
call_handler = std::move(call.handler)]() {
call_handler = std::move(call.handler)]() mutable {
call_destination_->StartCall(std::move(call_handler));
return CallOutboundLoop(stream_id, call_initiator);
});

@ -41,18 +41,18 @@ namespace grpc_core {
// PartySyncUsingAtomics
GRPC_MUST_USE_RESULT bool Party::RefIfNonZero() {
auto count = state_.load(std::memory_order_relaxed);
auto state = state_.load(std::memory_order_relaxed);
do {
// If zero, we are done (without an increment). If not, we must do a CAS
// to maintain the contract: do not increment the counter if it is already
// zero
if (count == 0) {
if ((state & kRefMask) == 0) {
return false;
}
} while (!state_.compare_exchange_weak(count, count + kOneRef,
} while (!state_.compare_exchange_weak(state, state + kOneRef,
std::memory_order_acq_rel,
std::memory_order_relaxed));
LogStateChange("RefIfNonZero", count, count + kOneRef);
LogStateChange("RefIfNonZero", state, state + kOneRef);
return true;
}

Loading…
Cancel
Save