rocksdb/utilities
Xingbo Wang bcaf2794dc Fix TSAN data race in InjectedErrorLog by suppressing benign races (#14467)
Summary:
InjectedErrorLog is a lock-free circular ring buffer designed to be safe to call from signal handlers (which cannot use locks). It has an intentional benign data race between Record() (called by worker threads) and PrintAll() (called by the main thread from a signal/termination handler). The code documents this trade-off in comments, but was missing TSAN suppression annotations.

Simply adding TSAN_SUPPRESSION (__attribute__((no_sanitize("thread")))) is insufficient because TSAN still intercepts libc functions like vsnprintf/snprintf -- accesses through these interceptors are still tracked even when the calling function is annotated.

The fix:
1. Add TSAN_SUPPRESSION to both Record() and PrintAll() to suppress direct field reads/writes in the function body.
2. Restructure both functions to use local stack buffers for vsnprintf/snprintf operations instead of operating directly on shared entry data. This avoids passing shared memory through TSAN-intercepted libc functions.

Also adds fault_injection_fs_test with a ConcurrentRecordAndPrintAll test that exercises the concurrent Record() + PrintAll() pattern and verifies no TSAN race is reported.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/14467

Test Plan:
- fault_injection_fs_test passes under TSAN (buck2 test fbcode//mode/dbg-tsan)
- Reverted fix, re-ran: Fatal (6 TSAN warnings) -- round-trip confirmed
- fault_injection_fs_test passes under debug mode (no regression)

Reviewed By: mszeszko-meta

Differential Revision: D96948483

Pulled By: xingbowang

fbshipit-source-id: efdd5eafa12a5a82f973e40aa327901cc5f95033
2026-03-19 09:40:02 -07:00
..
agg_merge Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
backup Set correct file_type in BackupInfo::file_details (#14464) 2026-03-18 12:01:29 -07:00
blob_db Restore blob_dump_tool compression support (partially revert PR #14266) (#14382) 2026-02-24 14:10:13 -08:00
cassandra Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
checkpoint Fix memory leak in ExportColumnFamily for empty column families (#14458) 2026-03-13 21:14:48 -07:00
compaction_filters Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
convenience Run clang-format on utilities/ (except utilities/transactions/) (#10853) 2022-10-24 16:38:09 -07:00
leveldb_options Put Cache and CacheWrapper in new public header (#11192) 2023-02-09 12:12:02 -08:00
memory Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
merge_operators Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
option_change_migration Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
options Remove deprecated SliceTransform::InRange() virtual method (#14353) 2026-02-19 16:45:51 -08:00
persistent_cache Fix string-conversion issue in internal_repo_rocksdb/repo/utilities/persistent_cache/block_cache_tier_file.cc +2 (#14312) 2026-02-09 09:21:12 -08:00
secondary_index Expose a simple secondary index implementation (#13370) 2025-02-05 15:43:54 -08:00
simulator_cache Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
table_properties_collectors Add an optional min file size requirement for deletion triggered compaction (#13707) 2025-06-19 11:04:35 -07:00
trace Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
transactions Fix TSAN data race in InjectedErrorLog by suppressing benign races (#14467) 2026-03-19 09:40:02 -07:00
trie_index Support all operation types in User Defined Index (UDI) interface (#14399) 2026-03-16 15:25:05 -07:00
ttl Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
write_batch_with_index Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
cache_dump_load.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
cache_dump_load_impl.cc Require C++20 (#13904) 2025-08-28 16:59:16 -07:00
cache_dump_load_impl.h Require C++20 (#13904) 2025-08-28 16:59:16 -07:00
compaction_filters.cc Remove FactoryFunc from LoadXXXObject (#11203) 2023-02-17 12:54:07 -08:00
counted_fs.cc Fix serious FSDirectory use-after-Close bug (missing fsync) (#10460) 2022-08-02 10:54:32 -07:00
counted_fs.h Explicitly closing all directory file descriptors (#10049) 2022-06-01 18:03:34 -07:00
debug.cc Remove deprecated DB::Open raw pointer variants (and more) (#14335) 2026-02-17 23:33:39 -08:00
env_mirror.cc Support GetFileSize API in FSRandomAccessFile (#13676) 2025-07-09 10:40:28 -07:00
env_mirror_test.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
env_timed.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
env_timed.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
env_timed_test.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
fault_injection_env.cc Revert "Create a new API FileSystem::SyncFile for file sync (#13762)" (#13987) 2025-09-22 15:30:24 -07:00
fault_injection_env.h Revert "Create a new API FileSystem::SyncFile for file sync (#13762)" (#13987) 2025-09-22 15:30:24 -07:00
fault_injection_fs.cc Add injected error log ring buffer for fault injection diagnostics (#14431) 2026-03-11 18:15:04 -07:00
fault_injection_fs.h Fix TSAN data race in InjectedErrorLog by suppressing benign races (#14467) 2026-03-19 09:40:02 -07:00
fault_injection_fs_test.cc Fix TSAN data race in InjectedErrorLog by suppressing benign races (#14467) 2026-03-19 09:40:02 -07:00
fault_injection_secondary_cache.cc Add some compressed and tiered secondary cache stats (#12150) 2023-12-15 11:34:08 -08:00
fault_injection_secondary_cache.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
memory_allocators.h Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
merge_operators.cc Remove FactoryFunc from LoadXXXObject (#11203) 2023-02-17 12:54:07 -08:00
merge_operators.h Run clang-format on utilities/ (except utilities/transactions/) (#10853) 2022-10-24 16:38:09 -07:00
object_registry.cc Reformat source files (#14331) 2026-02-13 11:56:22 -08:00
object_registry_test.cc Standardize on clang-format version 18 (#13233) 2024-12-19 10:58:40 -08:00
types_util.cc Add support in SstFileReader to get a raw table iterator (#12385) 2024-04-02 21:23:06 -07:00
types_util_test.cc Add support in SstFileReader to get a raw table iterator (#12385) 2024-04-02 21:23:06 -07:00
util_merge_operators_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
wal_filter.cc Remove FactoryFunc from LoadXXXObject (#11203) 2023-02-17 12:54:07 -08:00