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

Bun crashing when trying to await Bun.write inside test function #12360

Open
karlrobeck opened this issue Jul 5, 2024 · 3 comments · May be fixed by #12364
Open

Bun crashing when trying to await Bun.write inside test function #12360

karlrobeck opened this issue Jul 5, 2024 · 3 comments · May be fixed by #12364
Labels
crash An issue that could cause a crash runtime windows An issue that only occurs on Windows

Comments

@karlrobeck
Copy link

karlrobeck commented Jul 5, 2024

How can we reproduce the crash?

Hi, im trying to create a cli tool for executing .exe file on bun. i'm also trying to create a test for generating random .exe file so that my "validatePath" function could determine if that file path exist or not.

here is my validatePath function code

import { fileURLToPath, pathToFileURL } from "bun"

export async function validatePath(path: URL): Promise<URL | string> {

  const filePath = fileURLToPath(path)

  if (await Bun.file(filePath).exists()) {
    return pathToFileURL(filePath)
  } else {
    return ""
  }
}

i have two test, the first one test for invalid input

test("validate executable given in the config using `validatePath`: invalid value", async () => {

    const filePath = "./sample.exe"

    const newFilePath = await validatePath(pathToFileURL(filePath))

    expect(newFilePath).toBe("");
})

and for the second test, it will now generate a .exe file or any file.

test("validate executable given in the config using `validatePath`: expected real implementation", async () => {

  const editorPath: URL | string = pathToFileURL("./metaeditor64.exe")
  const terminalPath: URL | string = pathToFileURL("./terminal64.exe")

  await Bun.write(editorPath.pathname, "im a editor")
  await Bun.write(terminalPath.pathname, "im a terminal")

  const newEditorPath = <URL>await validatePath(editorPath)
  const newTerminalPath = <URL>await validatePath(terminalPath)

  expect(newEditorPath.pathname).toBe(editorPath.pathname)
  expect(newTerminalPath.pathname).toBe(terminalPath.pathname)
})

when running bun test. bun panics when trying to execute the second test

src\utils.test.ts:
✓ validatePath > validate executeable given in the config using `validatePath`: invalid value
============================================================
Bun v1.1.18 (5a0b9352) Windows x64
Args: "bun" "test"
Features: jsc tsconfig(2)
Elapsed: 67ms | User: 46ms | Sys: 62ms
RSS: 0.14GB | Peak: 0.14GB | Commit: 0.22GB | Faults: 33489

panic(main thread): Internal assertion failure
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

after further investigation. the main culprit on why bun is crashing is the Bun.write function.

await Bun.write(editorPath.pathname, "im a editor")
await Bun.write(terminalPath.pathname, "im a terminal")

trying to await Bun.write when testing cause the Bun runtime to panic.

Relevant log output

Bun v1.1.18 (5a0b9352) Windows x64
Args: "bun" "test"
Features: jsc tsconfig(2)
Elapsed: 73ms | User: 62ms | Sys: 93ms
RSS: 0.14GB | Peak: 0.14GB | Commit: 0.22GB | Faults: 33447

panic(main thread): Internal assertion failure
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Stack Trace (bun.report)

Bun v1.1.18 (5a0b935) on windows x86_64 [TestCommand]

panic: Internal assertion failure

@karlrobeck karlrobeck added the crash An issue that could cause a crash label Jul 5, 2024
@github-actions github-actions bot added runtime windows An issue that only occurs on Windows labels Jul 5, 2024
@Jarred-Sumner
Copy link
Collaborator

Unfortunately, for us to be able to potentially reproduce this - it will need all the code that is being executed when the crash occurs. The specific line causing the crash is not the line where it happens. The cause is happening earlier, and then only triggering at the next allocation or something along those lines. Can you send a .zip file or a Github repo we can run?

image

@karlrobeck
Copy link
Author

here is the source code that contains the code.

https://github.com/karlrobeck/Bun-write-error-test

i also tried the repo to my arch wsl to see if i can also reproduce the error. weird thing is that on my wsl system. it doesnt reproduce the error only on my windows system.

Arch wsl Bun 1.1.17

image

windows 10 Bun 1.1.18

image

Arch wsl Bun 1.1.18 (i upgraded it)

image

@Jarred-Sumner
Copy link
Collaborator

Jarred-Sumner commented Jul 5, 2024

Thank you. I am able to reproduce this on Windows.

index.test.ts:
 validate executable given in the config using `validatePath`: invalid value [0.20ms]
============================================================
Bun Canary v1.1.10-canary.1 (6566b8a6) Windows x64
Args: "C:\Users\window\.bun\bin\bun.exe", "test"
Features: jsc tsconfig
Elapsed: 36ms | User: 0ms | Sys: 0ms
RSS: 130.40MB | Peak: 130.40MB | Commit: 0.22GB | Faults: 32090

panic(main thread): Internal assertion failure
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.10/wt16566b8aAiggggEgz+6L+zhxIwgq5F+hwCi55nbm9izQyu3hI+4m4Ti25pL2j461CA0eNrzzCtJLcpLzFFILC5OLSrJzM9TSEvMzCktSgUAiSkKPg

PS C:\Temp\Bun-write-error-test> bun test^C
PS C:\Temp\Bun-write-error-test> bun-debug test
[SYS] NtCreateFile(80[cwd handle], \??\C:\Temp\Bun-write-error-test\bunfig.toml) = OBJECT_NAME_NOT_FOUND (file) = 12297829382473034410
bun test v1.1.19 (60d8e97c)
[SYS] NtCreateFile([invalid_fd], \??\C:\) = SUCCESS (dir) = 476
[SYS] NtQueryDirectoryFile(476[\Device\HarddiskVolume3\]) = 4270
[SYS] NtQueryDirectoryFile(476[\Device\HarddiskVolume3\]) = 0
[SYS] NtCreateFile([invalid_fd], \??\C:\Temp) = SUCCESS (dir) = 592
[SYS] NtQueryDirectoryFile(592[\Device\HarddiskVolume3\Temp]) = 2314
[SYS] NtQueryDirectoryFile(592[\Device\HarddiskVolume3\Temp]) = 0
[SYS] NtCreateFile([invalid_fd], \??\C:\Temp\Bun-write-error-test) = SUCCESS (dir) = 596
[SYS] NtQueryDirectoryFile(596[\Device\HarddiskVolume3\Temp\Bun-write-error-test]) = 922
[SYS] NtQueryDirectoryFile(596[\Device\HarddiskVolume3\Temp\Bun-write-error-test]) = 0
[SYS] GetFinalPathNameByHandle(anyopaque@254)
[SYS] NtCreateFile(596[\Device\HarddiskVolume3\Temp\Bun-write-error-test], \??\C:\Temp\Bun-write-error-test\package.json) = SUCCESS (file) = 600
[SYS] close(600[\Device\HarddiskVolume3\Temp\Bun-write-error-test\package.json])
[SYS] GetFinalPathNameByHandle(anyopaque@254)
[SYS] NtCreateFile(596[\Device\HarddiskVolume3\Temp\Bun-write-error-test], \??\C:\Temp\Bun-write-error-test\tsconfig.json) = SUCCESS (file) = 600
[SYS] close(600[\Device\HarddiskVolume3\Temp\Bun-write-error-test\tsconfig.json])
[SYS] NtCreateFile([invalid_fd], \??\C:\Temp\Bun-write-error-test) = SUCCESS (dir) = 612
[SYS] NtQueryDirectoryFile(612[\Device\HarddiskVolume3\Temp\Bun-write-error-test]) = 922
[SYS] NtQueryDirectoryFile(612[\Device\HarddiskVolume3\Temp\Bun-write-error-test]) = 0

index.test.ts:
[SYS] NtCreateFile(80[cwd handle], \??\C:\Temp\Bun-write-error-test\index.test.ts) = SUCCESS (file) = 632
[SYS] close(632[\Device\HarddiskVolume3\Temp\Bun-write-error-test\index.test.ts])
[SYS] NtCreateFile([invalid_fd], \??\C:\Temp) = SUCCESS (dir) = 672
[SYS] NtQueryDirectoryFile(672[\Device\HarddiskVolume3\Temp]) = 2314
[SYS] NtQueryDirectoryFile(672[\Device\HarddiskVolume3\Temp]) = 0
[SYS] NtCreateFile(80[cwd handle], \??\C:\Temp\Bun-write-error-test\index.ts) = SUCCESS (file) = 676
[SYS] close(676[\Device\HarddiskVolume3\Temp\Bun-write-error-test\index.ts])
[EventLoop] tickWithoutIdle
[jest] test("validate executable given in the config using `validatePath`: invalid value")
[EventLoop] enter() = 0
[alloc] new() = src.bun.js.webcore.blob.Blob.Store@50416340380
[alloc] new() = src.bun.js.webcore.blob.Blob@50416290500
[SYS] uv stat(C:\Temp\Bun-write-error-test\sample.exe) = -4058
[EventLoop] exit() = 0
✓ validate executable given in the config using `validatePath`: invalid value
[jest] test("validate executable given in the config using `validatePath`: expected real implementation")
[EventLoop] enter() = 0
[alloc] new() = src.bun.js.webcore.blob.Blob.Store@50416340460
[alloc] new() = src.bun.js.webcore.blob.Blob.Store@50416340540
[alloc] new() = src.bun.js.webcore.blob.WriteFile.WriteFileWindows@50416400380
[EventLoop] exit() = 0
[alloc] new() = src.bun.js.node.node_fs.Async.AsyncMkdirp@504162701b0
        bun.assert(this.err == null);
                  ^
C:\bun\src\bun.js\webcore\blob\WriteFile.zig:511:23: 0x7ff6fab541fa in onMkdirpComplete (bun-zig.o)
            this.throw(err);
                      ^
C:\bun\src\bun.js\event_loop.zig:218:66: 0x7ff6faaa8d69 in wrap (bun-zig.o)
                @call(bun.callmod_inline, Callback, .{@as(*Type, @ptrCast(@alignCast(this.?)))});
                                                                 ^
C:\bun\src\bun.js\event_loop.zig:202:17: 0x7ff6f93c8982 in run (bun-zig.o)
        callback(ctx.?);
                ^
C:\bun\src\bun.js\event_loop.zig:1035:28: 0x7ff6f93c1991 in tickQueueWithCount__anon_121510 (bun-zig.o)
                    any.run();
                           ^
C:\bun\src\bun.js\event_loop.zig:1249:39: 0x7ff6f8de487a in tickWithCount (bun-zig.o)
        return this.tickQueueWithCount("tasks");
                                      ^
C:\bun\src\bun.js\event_loop.zig:1473:42: 0x7ff6f8960605 in tick (bun-zig.o)
                while (this.tickWithCount() > 0) : (this.global.handleRejectedPromises()) {
                                         ^
C:\bun\src\cli\test_command.zig:1256:44: 0x7ff6f9a62de8 in run (bun-zig.o)
                        vm.eventLoop().tick();
                                           ^
C:\bun\src\cli\test_command.zig:1143:32: 0x7ff6f93b26b8 in begin (bun-zig.o)
                TestCommand.run(reporter, vm, files[files.len - 1].slice(), allocator, true) catch {};
                               ^

PS C:\Temp\Bun-write-error-test>

Jarred-Sumner added a commit that referenced this issue Jul 5, 2024
@Jarred-Sumner Jarred-Sumner linked a pull request Jul 5, 2024 that will close this issue
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 runtime windows An issue that only occurs on Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants