From 1f6d3189a9386cae59cb89f8e2eba9604a9c637e Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Tue, 13 Nov 2018 10:59:23 -0500 Subject: [PATCH] Fix data race in client_channel. Since retry_dispatched is next to the metadata bitfields, compiler will generate a 2 byte store when we set this bitfield. Move this field to the end of the structure to avoid such a data race. Fixes #16896 --- src/core/ext/filters/client_channel/client_channel.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index d42961fc608..8e9ee889e1d 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -1023,13 +1023,17 @@ struct subchannel_call_retry_state { bool completed_recv_initial_metadata : 1; bool started_recv_trailing_metadata : 1; bool completed_recv_trailing_metadata : 1; - // State for callback processing. - bool retry_dispatched : 1; subchannel_batch_data* recv_initial_metadata_ready_deferred_batch = nullptr; grpc_error* recv_initial_metadata_error = GRPC_ERROR_NONE; subchannel_batch_data* recv_message_ready_deferred_batch = nullptr; grpc_error* recv_message_error = GRPC_ERROR_NONE; subchannel_batch_data* recv_trailing_metadata_internal_batch = nullptr; + // State for callback processing. + // NOTE: Do not move this next to the metadata bitfields above. That would + // save space but will also result in a data race because compiler will + // generate a 2 byte store which overwrites the meta-data fields upon + // setting this field. + bool retry_dispatched : 1; }; // Pending batches stored in call data.