Skip to content

Solved another spec race condition with that effects JRuby#134

Merged
patvice merged 1 commit into
mainfrom
jruby-spec-racecondition-issue
Mar 5, 2026
Merged

Solved another spec race condition with that effects JRuby#134
patvice merged 1 commit into
mainfrom
jruby-spec-racecondition-issue

Conversation

@patvice
Copy link
Copy Markdown
Owner

@patvice patvice commented Feb 23, 2026

Problem
JRuby CI was intermittently failing in Cancellation Integration (stdio-native) due to concurrency races in cancellation paths. The failing spec relied on unsynchronized shared state between threads, which is more likely to flake on JRuby / cause issues in production settings though MRI should be safe to do it's thread model.

I also found a related runtime race where a cancellable operation could be marked running before its worker thread was safely published, causing cancellation to miss the thread in rare timing windows.

Solution

  • Made cancellation integration specs thread-safe by replacing shared mutable variables/arrays with Queue-based signaling.
  • Updated cancellation worker thread handling to tolerate TransportError during teardown races.
  • Fixed CancellableOperation to publish state and thread atomically under mutex, so cancellation always sees a consistent state.
  • Hardened concurrent state/value reads in Promise and AsyncResponse with synchronized accessors.
  • Added a small timeout helper cleanup improvement (kill + short join) to reduce orphaned worker threads after timeout.

@patvice patvice merged commit 4d10851 into main Mar 5, 2026
7 checks passed
@patvice patvice deleted the jruby-spec-racecondition-issue branch March 5, 2026 16:31
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