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>
This commit is contained in:
Jarred Sumner
2026-01-13 23:05:46 -08:00
committed by GitHub
parent 49d0fbd2de
commit 967a6a2021
3 changed files with 24 additions and 3 deletions

View File

@@ -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);

View File

@@ -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) },

View File

@@ -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 {