Repository navigation
fs.readdir: release pending_err mutex in recursive subtask error path - #32748
Conversation
AsyncReaddirRecursiveTask::perform_work acquired pending_err_mutex via
bun_threading::Mutex::lock(), which returns (), not a guard. The unit
binding meant the mutex was never unlocked. When a second failing subtask
ran on the same thread-pool worker the debug deadlock detector panicked
("Deadlock detected"); in release builds every other worker blocked on
the mutex forever, subtask_count never reached zero, and the returned
promise from fs.promises.readdir(path, {recursive: true}) never settled.
Use lock_guard() so the mutex is released when the scope exits.
|
Updated 3:46 AM PT - Jun 26th, 2026
✅ @autofix-ci[bot], your commit ccc086488efd8f845dca1e068f70ac7e564b3065 passed in 🧪 To try this PR locally: bunx bun-pr 32748That installs a local version of the PR into your bun-32748 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough
ChangesRecursive readdir error handling
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
LGTM — one-line swap from lock() (returns ()) to lock_guard() so the pending_err mutex actually releases; verified against the bun_threading::Mutex API.
Extended reasoning...
Overview
A single-token change in src/runtime/node/node_fs.rs: self.pending_err_mutex.lock() → self.pending_err_mutex.lock_guard() in the error path of AsyncReaddirRecursiveTask::perform_work. The field is a bun_threading::Mutex, whose lock() returns () (manual unlock() required) while lock_guard() returns an RAII MutexGuard that unlocks on drop — I verified both signatures in src/threading/Mutex.rs. Binding () to _lock meant the mutex was never released, so a second failing subtask would deadlock (debug panic / release hang). The accompanying test spawns a subprocess with 64 self-referencing symlinks to force many concurrent ELOOP failures and asserts the promise rejects cleanly within a 10s timeout.
Security risks
None. No new inputs, no auth/crypto/permissions surface; this only affects whether an internal mutex is released on an error path.
Level of scrutiny
Low. The diagnosis in the PR description is precise and matches the Mutex API in-tree, the fix is the minimal correct change, and the guard is held over exactly the same scope the original code intended. The test is run in a subprocess with a timeout so a regression can't hang CI.
Other factors
The robobun build-failure comment references the pre-autofix commit (3818d2d); an autofix commit (ccc0864) landed after, and the source change itself is trivially correct Rust that compiles by inspection. No outstanding human reviewer comments.
Problem
fs.promises.readdir(path, { recursive: true })hangs forever (release) or panicsDeadlock detectedon a thread-pool worker (debug) when two or more of its per-directory subtasks fail. The returned promise never settles, with nothing on stderr in a release build.Cause
AsyncReaddirRecursiveTask::perform_worktakes the per-taskpending_err_mutexon the error path withbun_threading::Mutex::lock()returns(), not a guard, so_lockis the unit value and the mutex is never released. The first failing subtask locks it and decrementssubtask_count; the next failing subtask on the same worker trips the debug deadlock detector (locking_thread == current_thread_id), and on any other worker blocks forever inFutexImpl::lock_slow.subtask_countnever reaches zero, sofinish_concurrentlynever runs and the user-facing promise never settles.This is the only site in the tree where a raw
bun_threading::Mutex::lock()result was bound to a variable; every otherlet _g = x.lock()pattern is onGuarded<T>,bun_core::Mutex<T>, orbun_alloc::Mutex, all of which return a real guard.Fix
Use
lock_guard()so the mutex is released when the scope exits.Verification
New test in
test/js/node/fs/fs.test.tscreates 64 self-referencing symlinks (each subtask'sopenat(..., O_DIRECTORY)fails withELOOP, which is not in the walker's swallowed set ofENOENT/ENOTDIR/EPERM) and asserts the spawned child rejects withELOOPand exits 0. Without the fix the child panics in debug and hangs in release; with it the promise rejects in well under a second.