mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
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:
@@ -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);
|
||||
|
||||
@@ -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) },
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user