Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node readdir causes Segmentation fault (or EBADF: Bad file descriptor) #12166

Open
chicken-suop opened this issue Jun 26, 2024 · 3 comments
Open
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux runtime

Comments

@chicken-suop
Copy link

How can we reproduce the crash?

Crash caused by this code running inside chokidar watching src

import { readdir, readFile, writeFile } from 'node:fs/promises';

const getMenuFilePaths = async (dir) => {
    let entries;
    try {
        entries = await readdir(dir, { withFileTypes: true });
    } catch (error) {
        logger.error(`Error reading directory ${dir}: ${error.message}`);
        return [];
    }
    const files = await Promise.all(entries.map(async entry => {
        const res = path.resolve(dir, entry.name);
        if (entry.isDirectory()) return getMenuFilePaths(res);
        if (['html', 'htm'].includes(fileName.split('.').pop().toLowerCase())) return res;
        return [];
    }));
    return files.flat();
};

getMenuFilePaths('src/foo')

When the try/catch is removed, this error is thrown many times:

EBADF: Bad file descriptor
   errno: -9
 syscall: "read"

Relevant log output

EBADF: Bad file descriptor
   errno: -9
 syscall: "read"





============================================================
Bun v1.1.17 (bb66bba1) Linux x64
Linux Kernel v6.2.0 | glibc v2.35
Args: "bun" "Build/Containers/static/builder/build.mjs" "-o" "Source" "-w"
Features: jsc Bun.stdin spawn transpiler_cache(6) tsconfig_paths tsconfig 
Builtins: "bun:main" "node:assert" "node:buffer" "node:child_process" "node:crypto" "node:events" "node:fs" "node:fs/promises" "node:os" "node:path" "node:stream" "node:string_decoder" "node:tty" "node:util" "node:util/types" "node:zlib" "node:worker_threads" 
Elapsed: 4295ms | User: 3864ms | Sys: 2093ms
RSS: 0.99GB | Peak: 0.32GB | Commit: 0.99GB | Faults: 0

panic(main thread): Segmentation fault at address 0x88E18
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.1.17/la1bb66bbaAqgggoH2lnhnE+xyQo1o6lD2xslgE______A2AwhniB

./watch: line 4: 891230 Illegal instruction     (core dumped) bun build.mjs -o src -w

Stack Trace (bun.report)

Bun v1.1.17 (bb66bba) on linux x86_64 [AutoCommand]

Segmentation fault at address 0x00088E18

@chicken-suop chicken-suop added the crash An issue that could cause a crash label Jun 26, 2024
@github-actions github-actions bot added linux An issue that occurs on Linux runtime labels Jun 26, 2024
@chicken-suop
Copy link
Author

chicken-suop commented Jun 26, 2024

I tried installing the linux-x64-baseline build (even though my CPU supports AVX2) by modifying the install script, but this didn't fix the issue

@chicken-suop
Copy link
Author

The issue was actually caused by running esbuild.build() in chokidar watch. Fixed by using esbuild's builtin watch method

@Jarred-Sumner
Copy link
Collaborator

Going to re-open this because it still seems to be a bug

@Jarred-Sumner Jarred-Sumner reopened this Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An issue that could cause a crash linux An issue that occurs on Linux runtime
Projects
None yet
Development

No branches or pull requests

2 participants