authorgravatar for doug.coleman@gmail.comDoug Coleman <doug.coleman@gmail.com> 2025-12-21 18:17:04-06:00
committergravatar for doug.coleman@gmail.comDoug Coleman <doug.coleman@gmail.com> 2025-12-21 20:11:05-06:00
log6b9125cbe662d530160e0732c856aa0da86894c0
tree7968821617128ab86b2b5e2d4d1081177c974942
parent8c5f731afbf2572f98b2840f3307e2c8a607d7a8

build_runner: fix race condition in dispatch_deps capacity reservation

Move ensureUnusedCapacity inside the mutex call to prevent a race condition where other worker threads could append to memory_blocked_steps between checking the length and iterating. repro branch: https://codeberg.org/erg/zig/src/branch/fix-30014-repro check out that branch, and depending on if you have the fix-30014 patch or not, it will either race condition or succeed Fixes #30014

1 files changed, 2 insertions(+), 1 deletions(-)

lib/compiler/build_runner.zig+2-1
......@@ -1410,12 +1410,13 @@ fn workerMakeOneStep(
14101410 if (s.max_rss != 0) {
14111411 var dispatch_deps: std.ArrayList(*Step) = .empty;
14121412 defer dispatch_deps.deinit(gpa);
1413 dispatch_deps.ensureUnusedCapacity(gpa, run.memory_blocked_steps.items.len) catch @panic("OOM");
14141413
14151414 {
14161415 run.max_rss_mutex.lockUncancelable(io);
14171416 defer run.max_rss_mutex.unlock(io);
14181417
1418 dispatch_deps.ensureUnusedCapacity(gpa, run.memory_blocked_steps.items.len) catch @panic("OOM");
1419
14191420 // Give the memory back to the scheduler.
14201421 run.claimed_rss -= s.max_rss;
14211422 // Avoid kicking off too many tasks that we already know will not have