oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.48k stars 2.78k forks source link

bun build --compile fails with EACCESS trying to write output #7515

Open humphd opened 11 months ago

humphd commented 11 months ago

What version of Bun is running?

1.0.15

What platform is your computer?

Linux 6.4.16-linuxkit aarch64 unknown (Linux Dev Contianer on MacOS))

What steps can reproduce the bug?

  1. Create a file, file.ts: console.log('hello world');
  2. Create an executable: bun build file.ts --compile --outfile ./file

What is the expected behavior?

I'd expect to have an executable created

What do you see instead?

 [13ms]  bundle  1 modules
error: failed to open temporary file to copy bun into
EACCES: Permission denied (open())

Additional information

The two calls that are failing in this strace are interesting, specifically:

[pid 19234] openat(AT_FDCWD, ".179e939cefeff7f3-00000000.bun-build", O_RDWR|O_CREAT|O_CLOEXEC, 000) = -1 EACCES (Permission denied)
[pid 19234] openat(AT_FDCWD, "/tmp.179e939cefeff7f3-00000000.bun-build", O_RDWR|O_CREAT|O_CLOEXEC, 000) = -1 EACCES (Permission denied)

I'm not clear why it can't write to . (I have permissions to do it), but should the second not be /tmp/.179e939cefeff7f3-00000000.bun-build (trying to write to the root)?

Full trace:

strace -e open,openat -f bun build parge.ts --compile --outfile ./parge2
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/aarch64-linux-gnu/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/proc/sys/vm/overcommit_memory", O_RDONLY) = 3
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/util/bunfig.toml", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, ".", O_RDONLY|O_NOCTTY|O_CLOEXEC|O_PATH|O_DIRECTORY) = 3
openat(AT_FDCWD, "/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/workspaces/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 4
openat(AT_FDCWD, "/workspaces/DeepStructure/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 5
openat(5, "package.json", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = 6
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 6
openat(6, "package.json", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = 7
openat(6, "tsconfig.json", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = 7
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/@ds/tsconfig/base.json", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/util/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 7
openat(AT_FDCWD, "/etc/localtime", O_RDONLY|O_CLOEXEC) = 6
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/node_modules/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 7
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/node_modules/parge.ts", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/workspaces/DeepStructure/ds/node_modules/parge.ts", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/workspaces/DeepStructure/node_modules/", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 7
openat(AT_FDCWD, "/workspaces/DeepStructure/node_modules/parge.ts", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/workspaces/DeepStructure/node_modules/parge.ts", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
strace: Process 19235 attached
strace: Process 19236 attached
[pid 19235] openat(AT_FDCWD, "/workspaces/DeepStructure/ds/util/parge.ts", O_RDONLY|O_NOCTTY|O_LARGEFILE|O_CLOEXEC) = 7
strace: Process 19237 attached
[pid 19234] openat(AT_FDCWD, "/workspaces/DeepStructure/ds/util", O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY) = 7
  [26ms]  bundle  1 modules
[pid 19234] openat(AT_FDCWD, ".179e939cefeff7f3-00000000.bun-build", O_RDWR|O_CREAT|O_CLOEXEC, 000) = -1 EACCES (Permission denied)
[pid 19234] openat(AT_FDCWD, "/tmp.179e939cefeff7f3-00000000.bun-build", O_RDWR|O_CREAT|O_CLOEXEC, 000) = -1 EACCES (Permission denied)
error: failed to open temporary file to copy bun into
EACCES: Permission denied (open())
[pid 19237] +++ exited with 1 +++
[pid 19236] +++ exited with 1 +++
[pid 19235] +++ exited with 1 +++
+++ exited with 1 +++

Afterward, I have the current files in my cwd:

ls -lah
ls: cannot access '.179e939cefeff7f3-00000000.bun-build': No such file or directory
ls: cannot access '.179e938f5defff5e-00000000.bun-build': No such file or directory
ls: cannot access '.179e939cc7af9fcb-00000000.bun-build': No such file or directory
ls: cannot access '.179e93cff5aeffff-00000000.bun-build': No such file or directory
total 8.0K
drwxr-xr-x  8 humphd humphd 256 Dec  7 14:30 .
drwxr-xr-x 17 humphd humphd 544 Dec  7 13:08 ..
-?????????  ? ?      ?        ?            ? .179e938f5defff5e-00000000.bun-build
-?????????  ? ?      ?        ?            ? .179e939cc7af9fcb-00000000.bun-build
-?????????  ? ?      ?        ?            ? .179e939cefeff7f3-00000000.bun-build
-?????????  ? ?      ?        ?            ? .179e93cff5aeffff-00000000.bun-build

I noticed this was also fixed for https://github.com/oven-sh/bun/issues/2944 in https://github.com/oven-sh/bun/commit/5bec0252a0223e45571f56dc49c240366df99852

paperdave commented 11 months ago

seems bun somehow created a corrupted file, maybe due to linuxkit

the fallback run it creates the file it is missing a / in the path. i can open a fix for that but im not sure about the first EACCES

jabnakar commented 10 months ago

dang this is happening in Windows too , very similar . I used ProcMon to trace and it shows these same folder/files. one difference is the error is "ENOENT"

paperdave commented 10 months ago

note that windows does not support --compile right now, though this bug might be shared.

jabnakar commented 10 months ago

yes i do note that , its not working on both Windows 11 and WSL(Ubuntu), its working on MacOS(Hackintosh). All on the same machine