Marton Greber has uploaded this change for review. (
http://gerrit.cloudera.org:8080/24012
Change subject: KUDU-3735: fix data race in SignalData init
......................................................................
KUDU-3735: fix data race in SignalData init
The std::atomic<T> in-class initializer syntax ({ kNotInUse }) and the
operator= assignment in libstdc++ (GCC) both emit a plain non-atomic
write to the underlying _M_i storage field. When paired with the atomic
compare_exchange_strong in HandleStackTraceSignal(), this constitutes
undefined behaviour (mixing non-atomic and atomic accesses to the same
memory location) and is detected by TSAN as a data race.
The race was reported in Impala which vendors this code and builds with
GCC 10.4.0 + libstdc++. Kudu's own TSAN build uses Clang 11 + libc++,
which emits an atomic store in the atomic<T> constructor and therefore
does not trigger the report.
Fix by:
- Replacing the in-class initializer with an explicit atomic store in
a user-defined constructor, ensuring the initialization is always
an atomic operation regardless of stdlib implementation.
- Setting data->stack before publishing data->queued_to_tid, and using
memory_order_release on the store so the signal handler is guaranteed
to observe a valid stack pointer whenever it observes the tid.
- Using explicit memory_order_acq_rel/acquire on the CAS in the signal
handler to pair clearly with the release store above.
Change-Id: I566c427aa835732af8c0ef686346a8cd40a1eca1
---
M src/kudu/util/debug-util.cc
1 file changed, 24 insertions(+), 5 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/12/24012/1
--
To view, visit http://gerrit.cloudera.org:8080/24012
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings
Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I566c427aa835732af8c0ef686346a8cd40a1eca1
Gerrit-Change-Number: 24012
Gerrit-PatchSet: 1
Gerrit-Owner: Marton Greber <[email protected]>