Skip to content

fix(config): Data race in config_watcher inotify fd access #397

Description

@kcenon

What

ThreadSanitizer detected a data race in config_watcher.h between:

  • cleanup_inotify() (main thread) writing to inotify_fd_ at line 451-452
  • watch_loop_linux() (watcher thread) reading inotify_fd_ at lines 464, 474

The inotify_fd_ member is a plain int accessed from multiple threads without synchronization.

Why

This is a real data race that can cause:

  • Reading a closed file descriptor
  • Use-after-close on the inotify fd
  • Undefined behavior under concurrent access

Currently suppressed via sanitizers/tsan_suppressions.txt (added in #396).

Where

  • include/kcenon/common/config/config_watcher.h lines 445-454 and 456-478

How

Option A: Use atomic for fd

Make inotify_fd_ and watch_fd_ atomic integers.

Option B: Signal-based shutdown

Use a pipe/eventfd to signal the watcher thread to stop.

Acceptance Criteria

  • TSan suppression for config_watcher removed
  • TSan CI passes clean without suppression
  • Config watcher tests still pass

Metadata

Metadata

Assignees

Labels

testingTesting related issues

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions