← Back to Pull requests

Fix premature semaphore handle closure in Windows IPC waits #262

Closed
unknown closed this pull request without merging on Nov 14, 2026 08:29 UTC
View on GitHub
unknown unknown commented on Nov 08, 2026 20:35 UTC
Author

Windows IPC queue synchronization can close a semaphore handle while a live thread still needs it.

A waiter records the handle, releases the queue mutex, and then enters the Windows wait call. If the thread is delayed between unlocking and waiting, another thread can retire the semaphore after its cleanup timeout. The original waiter can then use an invalid handle, or one that Windows has reused for a different object.

Track local waiters and keep their semaphore handles alive until the waiting path finishes. Release those references on success, cancellation, and exceptions so unused semaphores can still be reclaimed.

Also initialize the semaphore-retirement flag and make access to the lazily resolved semaphore-query function pointer atomic. Its atomic accesses can remain relaxed because the existing dispatcher publishes the pointer through its release/acquire pair; atomic access is still needed because initializers can run concurrently.

Add three tests in test/run/util_ipc_windows_sync.cpp. They exercise the actual synchronization implementation with real Windows handles while controlling wait scheduling and elapsed time. The test wrapper caps native waits at five seconds and reports a timeout as a failure of the current case, allowing the remaining cases to run.

Against the original code, the lifetime test detects that cleanup closes the handle before the waiting path finishes. With the fix, the handle remains open. Two further tests verify that cancelled and failed waits release their references and allow later cleanup.

All three tests pass on native Windows with MSYS2 GCC 16.2 and C++11. A temporary lost-notification test variant fails through the five-second timeout and then runs both remaining cases successfully.

Diff: 219 lines (+164 / -55) across 2 files Reviewer: Lastique Review duration: 7914m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.37) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 219 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.323
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #262"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.7% (MEDIUM) · Higher = larger blast radius
36.7%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.5% · Safe to merge
14.5%
Repository