[chttp2] Fix tsan race (#32576)

Noticed here:
https://source.cloud.google.com/results/invocations/779f3614-42bd-44bb-a00d-ab56f9749095/targets/%2F%2Ftest%2Fcore%2Fend2end:h2_full_test@retry_cancel4@poller%3Depoll1@experiment%3Devent_engine_client/log

A race between starting reading and transport close.

Fix: move the closure setting inside the combiner, and check if the
transport is closed at that time.

<!--

If you know who should review your pull request, please assign it to
that
person, otherwise the pull request would get assigned randomly.

If your pull request is for a specific language, please add the
appropriate
lang label.

-->
pull/32586/head
Craig Tiller 2 years ago committed by GitHub
parent febed5121a
commit 2df6ca26dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc

@ -3116,9 +3116,24 @@ void grpc_chttp2_transport_start_reading(
grpc_slice_buffer_move_into(read_buffer, &t->read_buffer);
gpr_free(read_buffer);
}
t->notify_on_receive_settings = notify_on_receive_settings;
t->notify_on_close = notify_on_close;
t->combiner->Run(
GRPC_CLOSURE_INIT(&t->read_action_locked, read_action_locked, t, nullptr),
grpc_core::NewClosure([t, notify_on_receive_settings,
notify_on_close](grpc_error_handle) {
if (!t->closed_with_error.ok()) {
if (notify_on_receive_settings != nullptr) {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_on_receive_settings,
t->closed_with_error);
}
if (notify_on_close != nullptr) {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_on_close,
t->closed_with_error);
}
GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action");
return;
}
t->notify_on_receive_settings = notify_on_receive_settings;
t->notify_on_close = notify_on_close;
read_action_locked(t, absl::OkStatus());
}),
absl::OkStatus());
}

Loading…
Cancel
Save