Fix CFRunLoop timeouts breaking under coarse-resolution CLOCK_MONOTONIC #5485
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 · 216 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.322
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5485"
general
weight: 0.35
weissi
This fixes an issue affecting Linux/BSD/WASI where the TSR rate in
CFDate.cmay be incorrect. This rate is derived from the resolution ofCLOCK_MONOTONIC, but on some systems this clock has coarser resolution. It's used by a shim ofmach_absolute_time()and multiplied by a constant factor that assumes a more granular resolution, so on systems with coarser resolution the times will be incorrect.Fixes rdar://139710145
Motivation:
The practical scenario where this bug has been observed most often is when running XCTests in Linux via Docker on macOS. Linux Docker uses a clock with a coarser-resolution
CLOCK_MONOTONICthan "bare metal" Linux. This leads to timeout calculation errors in Foundation'sRunLoop, which XCTest relies on heavily for many features including handlingasynctest methods. The end result is that trivial XCTest suites involvingasyncmethods can hang in this environment once every 1-4 attempts.Modifications:
Stop using
clock_getres(CLOCK_MONOTONIC, ...)to determine TSR rate on Linux (and the other affected platforms in this#ifbranch) and instead hardcode the same rate that is used in themach_absolute_time()shim above,NSEC_PER_SEC.Result:
The XCTest hang no longer reproduces after many thousands of attempts in a loop, after reliably reproducing after 1-4 attempts previously.
Testing:
Verified via testing above.