deno
b2d8713a - fix(ext/node): tolerate unreadable cwd in require._nodeModulePaths (#34542)

Commit
177 days ago
fix(ext/node): tolerate unreadable cwd in require._nodeModulePaths (#34542) ## Summary `op_require_node_module_paths` always called `env_current_dir()` for non-`file:///` paths, even when the incoming `from` was already absolute. On macOS, `getcwd(3)` walks the directory tree from `/` and fails with `EACCES` if any ancestor is unreadable — e.g. running under `su nonadmin -c "..."` from a directory the unprivileged user can't read, the scenario from denoland/deno#21585. That cwd lookup then bubbled up as `NotFound: Unable to get CWD`, crashing `createRequire(import.meta.url)` (which deno injects when `deno -e` is spawned as a child process via `child_process.spawn`) even though the absolute `import.meta.url` path didn't need cwd at all. Skip the cwd lookup when `from` is already absolute. The previous fix #33587 made `Eval`/`Repl` fall back to a sentinel cwd at the workspace-factory layer, but the node-compat require ops sat below that and re-fetched cwd directly. ## Test plan Enables and passes two previously-skipped Node compat tests that spawn `deno -e 0` with the parent's cwd already unlinked (the same failure mode as the original macOS bug, just reachable on Linux): - `parallel/test-cwd-enoent.js` - `parallel/test-cwd-enoent-preload.js` `parallel/test-cwd-enoent-repl.js` (already enabled by #33587) continues to pass. ``` $ cargo test --test node_compat test-cwd-enoent test node_compat::parallel::test-cwd-enoent-preload.js ... ok test node_compat::parallel::test-cwd-enoent-repl.js ... ok test node_compat::parallel::test-cwd-enoent.js ... ok ``` Closes denoland/orchid#284 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading