From 967a6a2021d64fec9074e5131cf8b2bb3b07562e Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Tue, 13 Jan 2026 23:05:46 -0800 Subject: [PATCH] Fix blocking realpathSync call (#26056) ### What does this PR do? ### How did you verify your code works? --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- src/bun.js/bindings/c-bindings.cpp | 2 +- src/bun.js/node/node_fs.zig | 4 +++- test/js/node/fs/fs.test.ts | 21 ++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/bun.js/bindings/c-bindings.cpp b/src/bun.js/bindings/c-bindings.cpp index cfd507e78f..71c3e46c79 100644 --- a/src/bun.js/bindings/c-bindings.cpp +++ b/src/bun.js/bindings/c-bindings.cpp @@ -73,7 +73,7 @@ extern "C" bool is_executable_file(const char* path) { #if defined(O_EXEC) // O_EXEC is macOS specific - int fd = open(path, O_EXEC | O_CLOEXEC, 0); + int fd = open(path, O_EXEC | O_CLOEXEC | O_NONBLOCK | O_NOCTTY, 0); if (fd < 0) return false; close(fd); diff --git a/src/bun.js/node/node_fs.zig b/src/bun.js/node/node_fs.zig index 0baa7b8a94..d8b27f6cf6 100644 --- a/src/bun.js/node/node_fs.zig +++ b/src/bun.js/node/node_fs.zig @@ -5499,7 +5499,9 @@ pub const NodeFS = struct { // O_PATH is faster bun.O.PATH else - bun.O.RDONLY; + // O_NONBLOCK prevents blocking on a FIFO. + // O_NOCTTY prevents acquiring a controlling terminal. + bun.O.RDONLY | bun.O.NONBLOCK | bun.O.NOCTTY; const fd = switch (bun.sys.open(path, flags, 0)) { .err => |err| return .{ .err = err.withPath(path) }, diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index f4196f282f..d85c6a2aa7 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -1,5 +1,16 @@ import { describe, expect, it, spyOn } from "bun:test"; -import { bunEnv, bunExe, gc, getMaxFD, isBroken, isIntelMacOS, isWindows, tempDirWithFiles, tmpdirSync } from "harness"; +import { + bunEnv, + bunExe, + gc, + getMaxFD, + isBroken, + isIntelMacOS, + isPosix, + isWindows, + tempDirWithFiles, + tmpdirSync, +} from "harness"; import { isAscii } from "node:buffer"; import fs, { closeSync, @@ -51,6 +62,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { spawnSync } from "bun"; +import { mkfifo } from "mkfifo"; import { ReadStream as ReadStream_, WriteStream as WriteStream_ } from "./export-from.js"; import { ReadStream as ReadStreamStar_, WriteStream as WriteStreamStar_ } from "./export-star-from.js"; @@ -1540,6 +1552,13 @@ it("symlink", () => { expect(realpathSync(actual)).toBe(realpathSync(import.meta.path)); }); +it.if(isPosix)("realpathSync doesn't block on FIFO", () => { + const path = join(tmpdirSync(), "test-fs-fifo-block.fifo"); + mkfifo(path, 0o666); + realpathSync(path); + unlinkSync(path); +}); + it("readlink", () => { const actual = join(tmpdirSync(), "fs-readlink.txt"); try {