parallel: check a window handle's generation in torb_region_get/set #253
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
A
Windowhandle that outlives its region fails loudly (panic with a clear message) instead of reading NULLdataor writing into the memory of a reused region slot. The panicking-body hang is split out to #258.Context
Follow-up of #4 / PR #248 (merged as
f9b867d0), disclosed there. Located onmain:runtime/task.ctorb_region_get(~3093) andtorb_region_set(~3106) takestate = torb_region_of(region)and usestate->element/state->datawithout comparingtorb_region_generation_of(region)tostate->generation.torb_region_claimis the only function that checks it.torb_region_joinbumps the generation and setsdata = NULL, then returns the slot to the free list. After that a stalegetreadsNULL + offset, and oncetorb_region_openreuses the slot a stalesetwrites into another region's list (with that region'selement).torb_region_setalso does no bounds check of its own;Window.set(std/parallel/src/lib.trb~600) is the only guard. Addpositionvslengththere too, since the C function is public inruntime/include/torb_natives.h.std/parallel(regionItem,storeRegionItem) and the VM wrappers inruntime/machine_natives.c(~2231, ~2264); both call the same C functions, so one fix covers native and VM.Fix
Check the generation (and
data != NULL) understate->lockin both functions andtorb_panic_text("a window outlived itswindowsregion", torb_location_unknown)on mismatch.torb_region_getkeeps returningfalseonly for an out-of-range position. Mind thatgetis a hot path: one lock-protected compare per item; measure with the existing parallel conformance cases, and if it matters read the generation withtorb_atomic_loadinstead (decide in the PR).Acceptance criteria
torb_region_get(region ended) panics with the message above (runtime/tests/pool_test.c:region_stale_get_panics, under the recovering harness).torb_region_setpanics, also after the slot was reused by a new region, and the new region's items are unchanged (region_stale_set_after_reuse_panics).torb_region_setrejects a position outside the list (region_set_out_of_range_panics).compiler/tests/windows.test.trb,tests/conformance/parallel-windows-*) are unchanged and green; no measurable slowdown inparallel-windows-count.Dependencies
#4 (PR #248) is merged; none open. Independent of #258.
Seed
None. Runtime-only (
runtime/task.c,runtime/tests/pool_test.c): no syntax, no new native, no signature change, no std name the compiler looks up by string. Confirmed by readingstd/parallel/src/lib.trband the native declarations.Risk
Low. Adds a panic path only for handles that were already undefined behaviour. The hot-path cost is the one thing to check.
[loop:torbscript] intake: in scope (filed by the loop from the non-blocking findings of the review of PR #248), not a duplicate. Depends on #4. next: waiting (dependency #4) until 2026-10-10T04:00:00Z
Windowandwindows(CONCURRENCY slice F, gap 6) #4[loop:torbscript] dependency #4 is closed (PR #248 merged as
f9b867d0). next: refine (retry when the ready buffer has room)[loop:torbscript] claim refine by session:loop-torbscript-20261009 until 2026-10-09T09:25Z
windowsbody on a helper worker must not hang the join #258parallel: check a window's generation in region get/set, and a panicking body must not hang the jointo parallel: check a window handle's generation in torb_region_get/set[loop:torbscript] refine: both problems located on main by reading runtime/task.c and std/parallel. Generation check missing in torb_region_get/set (this issue); panic in a helper body skips finishWindow so torb_region_join spins forever (split into #258). Seed impact: none for both (runtime only). Criteria, tests, risk in the body. next: ready
[loop:torbscript] claim implement by session:loop-torbscript-20261009 until 2026-10-09T13:30Z
windows#259[loop:torbscript] close: PR #259 merged by argus (merge commit
ac5763d8), issue closed. Claim released. #258 follows.