Skip to content

fix(source): armWatchdog self-join guard no longer races the thread assignment (0.34.1) - #200

Merged
facontidavide merged 1 commit into
mainfrom
fix/watchdog-rearm-guard-race
Sep 14, 2026
Merged

facontidavide merged 1 commit into
mainfrom
fix/watchdog-rearm-guard-race

Conversation

@facontidavide

Copy link
Copy Markdown
Contributor

Why

PJ4's widened ThreadSanitizer lane (PlotJuggler/PJ4#649) now runs the SDK's own tests and reports a data race in ProviderJobTest.RearmingTheWatchdogFromOnExpireIsANoOp:

  • Write by the body thread: state_.watchdog = std::thread(...) in JobControl::armWatchdog.
  • Read by the watchdog thread: the self-join guard state_.watchdog.joinable() && state_.watchdog.get_id() == this_thread::get_id(), reached when on_expire re-arms.

The started semaphore orders the watchdog's release before the body's acquire, not the body's assignment before the watchdog's later read, so nothing publishes the write. Benign in practice (the read happens ≥ timeout later) but a genuine race.

Fix

The guard keys on a thread_local flag the watchdog thread sets before running on_expire, instead of reading the thread object. Behaviour is unchanged: re-arming from inside on_expire stays a no-op.

Version

PATCH → 0.34.1 (consumer-visible bug fix, no ABI/API change). PJ4 will bump its pin and drop the temporary race:PJ::sdk::source::JobControl::armWatchdog suppression it carries meanwhile.

🤖 Generated with Claude Code

…ssignment (0.34.1)

The guard read state_.watchdog on the watchdog thread inside on_expire while
the body thread was still move-assigning that member; the start semaphore
orders only the other direction. Key the guard on a thread_local flag set by
the watchdog thread before it runs on_expire.

Reported by ThreadSanitizer via ProviderJobTest.RearmingTheWatchdogFromOnExpireIsANoOp.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@facontidavide
facontidavide merged commit 4d59e7d into main Sep 14, 2026
7 checks passed
@facontidavide
facontidavide deleted the fix/watchdog-rearm-guard-race branch September 14, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant