WIP: Fix ref counting bugs in spawn API observed under rr
What does this PR do?
This fixes use-after-free bugs which I observed running worker_threads.test.ts under rr. I unfortunately have no idea how to repro this outside of rr so there's no test.
- Makes ProcessAutoKiller ref and deref the processes it monitors
- Fixes Process not getting re-ref'd in
rewatchPosixin some cases
How did you verify your code works?
Will see if CI passes
:x: @Jarred-Sumner, your commit 63263d3463b8fd55eb92ec27a881a959801598a3 has 1 failures in Build #18629:
test/js/bun/spawn/spawn.test.ts- 1 failing on 🪟 2019 x64test/js/bun/spawn/spawn.test.ts- 1 failing on 🪟 2019 x64-baseline
🧪 To try this PR locally:
bunx bun-pr 20191
That installs a local version of the PR into your bun-20191 executable, so you can run:
bun-20191 --bun
This leaks memory if it goes through on the WaiterThread.shouldUseWaiterThread code path due to the ref call on this line:
https://github.com/oven-sh/bun/blob/48cb2889b84552226c089b522dad42ec81498bd6/src/bun.js/api/bun/process.zig#L370-L375
Maybe instead, rewatchPosix in the success case should this.ref()?
https://github.com/oven-sh/bun/blob/48cb2889b84552226c089b522dad42ec81498bd6/src/bun.js/api/bun/process.zig#L272-L278
Maybe instead, rewatchPosix in the success case should this.ref()?
That sounds good, we'll see if it works