Skip to content

Bun.file(path).text() throws error: EBADF #1446

Closed

Description

@terrywh

What version of Bun is running?

v0.2.2

What platform is your computer?

Linux 5.4.119-1-tlinux4-0010.1 #1 SMP Thu Aug 25 10:21:45 CST 2022 x86_64 x86_64

What steps can reproduce the bug?

create a file "test.js" with the following:

// test.js
console.log(await Bun.file("./test.txt").text())

and a "test.txt" file with anything, eg:

// test.txt
hello

How often does it reproduce? Is there a required condition?

always.

What is the expected behavior?

open the file "test.txt" and output the content of it.

What do you see instead?

error: EBADF
   path: "./test.js"
syscall: "open"

Additional information

it seems the same code works on MacOS (with the same version v0.2.2)
image

Activity

  1. added
    bugSomething isn't working
    needs reproNeeds an example to reproduce
    on Nov 2, 2022
  2. Electroid commented on Nov 10, 2022

    @Electroid
  3. robobun commented on Nov 10, 2022

    @robobun
  4. Electroid commented on Nov 10, 2022

    @Electroid
  5. robobun commented on Nov 10, 2022

    @robobun
  6. Electroid commented on Nov 10, 2022

    @Electroid
  7. ConProgramming commented on Jan 19, 2023

    @ConProgramming

    Confirming this still is happening on Codespaces instances, await file("./example.txt").text()

    error: EBADF
       path: "./example.txt"
    syscall: "open"
    
  8. robobun commented on Jan 19, 2023

    @robobun
  9. Jarred-Sumner commented on Jan 19, 2023

    @Jarred-Sumner
    Collaborator

    wonder what linux kernel version is being used in Codespaces and if that supports io_uring

  10. terrywh commented on Feb 17, 2023

    @terrywh
    Author

    on "5.4.119-1-tlinux4-0009-eks #1 SMP Wed Sep 28 23:05:45 CST 2022 x86_64 x86_64 x86_64 GNU/Linux" bun v0.5.6 triggers the same "EBADF" problem

  11. lichenchenisapuppy commented on Mar 7, 2023

    @lichenchenisapuppy

    on "5.4.119-1-tlinux4-0009-eks #1 SMP Wed Sep 28 23:05:45 CST 2022 x86_64 x86_64 x86_64 GNU/Linux" bun v0.5.6 triggers the same "EBADF" problem

    我遇到了同样的问题
    bun v0.5.7
    linux mint 20.1

    试试:
    // test.js
    console.log(await Bun.readableStreamToText(Bun.file("./test.txt").stream()))

  12. terrywh commented on Jul 21, 2023

    @terrywh
    Author

    using the above test code, the problem continues (on v0.6.14 ~ v1.0.7)

    import { writeFileSync } from "node:fs";
    import { file } from "bun";
    
    writeFileSync("./example.txt", "this is an example file");
    console.log(await file("./example.txt").text());
    • this is running on a virtual machine, which failed with an error EBADF :

    Linux vm-centos 5.4.119-1-tlinux4-0010.3 #1 SMP Thu Jan 5 17:31:23 CST 2023 x86_64 x86_64 x86_64 GNU/Linux;

    image
    • the same code runs without error but with ** no output ** in a docker container:

    Linux docker-ctr-0 4.14.105-1-tlinux3-0020 #1 SMP Thu Apr 1 17:55:25 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

    image
  13. 5 remaining items

  14. joshunrau commented on Sep 27, 2023

    @joshunrau

    I tested this example on Docker and I cannot reproduce. Is it safe to assume this is fixed now?

  15. NoRKin commented on Sep 28, 2023

    @NoRKin

    Still not working on bun 1.0.3 / Ubuntu 20.04

  16. Tjerk-Haaye-Henricus commented on Sep 30, 2023

    @Tjerk-Haaye-Henricus

    +1 Its happening on a remix app that uses tailwind too.

    image
  17. LoGwi-N commented on Oct 5, 2023

    @LoGwi-N

    I have the same problem (

  18. cyr-l commented on Oct 5, 2023

    @cyr-l

    @LoGwi-N In the meantime, const text = await Bun.readableStreamToText(file.stream()); is working for me.

  19. LoGwi-N commented on Oct 5, 2023

    @LoGwi-N

    @LoGwi-N In the meantime, const text = await Bun.readableStreamToText(file.stream()); is working for me.

    Wonderfull, it's working.

  20. mrGibi commented on Oct 12, 2023

    @mrGibi

    Same on M1 Mac, inside the oven/bun docker container running Vite 😔

  21. StrongTS commented on Oct 13, 2023

    @StrongTS

    @cbioley, const text = await Bun.readableStreamToText(file.stream()); is working for me.
    thank you it's working. Ubuntu 20.04
    const file = Bun.file(filePath);
    if (!file) {
    throw new Error(Failed to load ${filePath});
    }
    const stream = await file.stream();
    const contents = await Bun.readableStreamToText(stream)
    console.log(contents);

  22. antoniobergas commented on Oct 18, 2023

    @antoniobergas

    Hi! Not 100% sure if its the right place but I see all Bad file descriptor issue are linked here.

    I'm building a CLI with Bun and I read and write into package.json with it.

    At running the tests on the pipeline, this Bad file descriptor issue shows up while in local everything works as expected.

    After replace Bun.file and Bun.write with the node:fs replacements, local still works and now its working properly in the pipeline also.

    Same ubuntu and linux version in local and the agent of the pipeline.

    As I said not 100% if its related but it's clear that something it's not working properly with those functions.

    Hope this info helps to fix it and thanks for the hard work! 😊

  23. small-angel commented on Oct 28, 2023

    @small-angel
    Contributor

    just want to note i have had cases where i've run into EBADF inside docker containers. it's hard to figure out exactly what is going on, but i suspect its from some file descriptor reuse, but it wouldn't explain why it's docker only. also, ive found that most fs functions can repro it if the situation is right, like readFileSync/writeFileSync/etc

    does anyone get this issue outside of Docker? my case might be different if this issue happens outside of docker.

  24. terrywh commented on Nov 1, 2023

    @terrywh
    Author

    using the above test code, the problem continues (on v0.6.14 ~ v1.0.7)

    import { writeFileSync } from "node:fs";
    import { file } from "bun";
    
    writeFileSync("./example.txt", "this is an example file");
    console.log(await file("./example.txt").text());
    • this is running on a virtual machine, which failed with an error EBADF :

    Linux vm-centos 5.4.119-1-tlinux4-0010.3 #1 SMP Thu Jan 5 17:31:23 CST 2023 x86_64 x86_64 x86_64 GNU/Linux;

    image * the same code runs without error but with ** no output ** in a docker container:

    Linux docker-ctr-0 4.14.105-1-tlinux3-0020 #1 SMP Thu Apr 1 17:55:25 CST 2021 x86_64 x86_64 x86_64 GNU/Linux

    image

    @Paperdave i have a vm and a docker container, but with slightly different situation.

  25. eslym commented on Nov 2, 2023

    @eslym

    Same here on digitalocean droplet

    • OS Linux 5.4.0-166-generic x86_64 x86_64
    • Bun 1.0.7+b0393fba6200d8573f3433fb0af258a0e33ac157

    Same result produced with different users and different file permissions

    image

  26. chicken-suop commented on Jun 24, 2024

    @chicken-suop

    I'm still getting this in Bun v1.1.16 (Linux x64) with await file('file.txt').text() running in chokidar watch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingbun.jsSomething to do with a Bun-specific API

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions