ReviewOS

zig-utils/zig-js

TSan: use typed atomic bits for shared Date payloads

#126
Closed chris opened this 9 days ago ·
9 days ago

Related: #123, #124

Combined main CI run 29462319298 passes the former rare-sidecar tsan-unit and tsan-threadfuzz failures but still reports one race in tsan-nogil-corpus (shard 1/4), exact case cve/mc-tear-date-cache.js.

The reader is Object.dateMs and the writer is Object.setDateMs at the same Date payload word. Both source accesses use raw @atomicLoad/@atomicStore(f64, ...), but CI's newer Zig 0.17 dev compiler lowers the f64 read through __tsan_memcpy while recognizing the store as atomic. Local Zig dev.956 did not expose this compiler-version-sensitive lowering.

Scope / acceptance

  • Store the exact IEEE-754 Date value bits in std.atomic.Value(u64) and bit-cast at the accessor boundary.
  • Preserve NaN payloads, infinities, signed zero, Date semantics, sidecar layout, and the one-time rare-state publication protocol.
  • Pass focused Date semantics and the exact TSan corpus case locally.
  • Pass the replacement full-main TSan no-GIL corpus gate.
9 days ago

Implemented and pushed to main in 4bad7a7. Date [[DateValue]] is now stored as std.atomic.Value(u64) and bit-cast at the accessor boundary, avoiding the newer Zig compiler's non-atomic f64 memcpy lowering while preserving every IEEE-754 bit. Local gates: 9/9 Date-focused semantic tests, zero leaks; exact TSan cve/mc-tear-date-cache.js 1/1, no sanitizer report. Leaving open for the replacement full-main corpus gate.

9 days ago

Replacement run 29463400611 showed that Zig dev.1413 still materialized the active union payload through __tsan_memcpy before inlining std.atomic.Value(u64).load; the writer was correctly atomic, but the union projection made the read plain.

Follow-up 859adaf9 takes a typed pointer directly to the active union payload's u64 storage and issues @atomicLoad/@atomicStore there.

Validation:

  • focused Date semantics: 9/9, zero leaks;
  • exact local TSan corpus case: 1/1 pass, no report.

Fresh full-main gate: https://github.com/zig-utils/zig-js/actions/runs/29464204902

9 days ago

CI run 29465812082 proved Zig dev.1413 emits __tsan_memcpy even while forming the address of the active union field, before the explicit atomic RMW. Follow-up daf74724 removes that compiler-sensitive access entirely: the Date atomic bits now live beside the stable rare union, initial bits precede release-publication of the Date tag, and reads use a zero-effect typed atomic RMW. Validation: 9/9 Date tests, focused Date basics, and exact local TSan cve/mc-tear-date-cache.js all pass. Awaiting the replacement shard-1 gate.

9 days ago

Completed by 4bad7a75, 859adaf9, aad7bdb1, and the compiler-proof layout fix daf74724. All Date tests and the exact local TSan case pass; replacement main run 29466730465 passed suppression-free TSan corpus shard 1 (59/59) on Zig dev.1413 in 19m05s, including cve/mc-tear-date-cache.js.

Sign in to comment on this issue.