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 build --compile cause segmentation fault #3764

Closed
azu opened this issue Jul 23, 2023 · 4 comments
Closed

bun build --compile cause segmentation fault #3764

azu opened this issue Jul 23, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@azu
Copy link

azu commented Jul 23, 2023

What version of Bun is running?

0.7.0

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

git clone https://github.com/azu/bun-build--tryfabricmartian
cd bun-build--tryfabricmartian
bun install
bun build ./index.ts --compile --outfile mycli
[1]    8254 segmentation fault  bun build ./index.ts --compile --outfile mycli

index.ts:

import { markdownToRichText } from "@tryfabric/martian";

console.log("Hello via Bun!", markdownToRichText);

What is the expected behavior?

output single executable binary

What do you see instead?

segmentation fault

bun build ./index.ts --compile --outfile mycli
[1]    8254 segmentation fault  bun build ./index.ts --compile --outfile mycli

Additional information

https://github.com/azu/bun-build--tryfabricmartian is a reproduce repository.

I noticed this segmentation fault when importing @tryfabric/martian.
It was not a problem with other packages, so there might be something wrong with this package.

Also, bun run works fine.

$ bun run ./index.ts
Hello via Bun! [Function]
@azu azu added the bug Something isn't working label Jul 23, 2023
@Jarred-Sumner
Copy link
Collaborator

Thank you for filing with a repro

panic in debug build:

uh-oh: index out of bounds: index 4294967295, len 146
bun will crash now 😭😭😭

----- bun meta -----
Bun v0.7.1_debug (f5289f50) macOS Silicon 22.3.0
BuildCommand: 
Elapsed: 20ms | User: 54ms | Sys: 16ms
RSS: 50.94MB | Peak: 50.94MB | Commit: 72.50MB | Faults: 60
----- bun meta -----

0   0x105744a68 WTFGetBacktrace
1   ??? Bun__crashReportDumpStackTrace
2   ??? src.report.fatal
3   ??? src.main.panic
4   ??? debug.panic__anon_3514
5   ??? debug.panicImpl
6   ??? src.bundler.bundle_v2.BundleV2.findReachableFiles.Visitor.visit__anon_64439
7   ??? src.bundler.bundle_v2.BundleV2.findReachableFiles.Visitor.visit__anon_64439
8   ??? src.bundler.bundle_v2.BundleV2.findReachableFiles.Visitor.visit__anon_64439
9   ??? src.bundler.bundle_v2.BundleV2.findReachableFiles.Visitor.visit__anon_64439
10  ??? src.bundler.bundle_v2.BundleV2.findReachableFiles.Visitor.visit__anon_64439
11  ??? src.bundler.bundle_v2.BundleV2.findReachableFiles
12  ??? src.bundler.bundle_v2.BundleV2.generateFromCLI
13  ??? src.cli.build_command.BuildCommand.exec
14  ??? src.cli.Command.start
15  ??? src.cli.Cli.start__anon_3833
16  ??? src.main.main

Crash report saved to:
  ~/.bun/.bun-crash/v0.7.1_debug-1690109213750.crash

Search GitHub issues https://bun.sh/issues or ask for #help in https://bun.sh/discord

thread 39839574 panic: index out of bounds: index 4294967295, len 146
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:390:61: 0x105bcb1e7 in visit__anon_64439 (bun-debug)
                            while (getRedirectId(v.redirects[other_source.get()])) |redirect_id| : (redirect_count += 1) {
                                                            ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:403:36: 0x105bcb3bf in visit__anon_64439 (bun-debug)
                            v.visit(import_record.source_index, check_dynamic_imports and import_record.kind == .dynamic, check_dynamic_imports);
                                   ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:403:36: 0x105bcb3bf in visit__anon_64439 (bun-debug)
                            v.visit(import_record.source_index, check_dynamic_imports and import_record.kind == .dynamic, check_dynamic_imports);
                                   ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:403:36: 0x105bcb3bf in visit__anon_64439 (bun-debug)
                            v.visit(import_record.source_index, check_dynamic_imports and import_record.kind == .dynamic, check_dynamic_imports);
                                   ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:403:36: 0x105bcb3bf in visit__anon_64439 (bun-debug)
                            v.visit(import_record.source_index, check_dynamic_imports and import_record.kind == .dynamic, check_dynamic_imports);
                                   ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:444:34: 0x105bca94b in findReachableFiles (bun-debug)
                    visitor.visit(entry_point, false, comptime check_dynamic_imports);
                                 ^
/Users/jarred/Code/bun/src/bundler/bundle_v2.zig:1034:60: 0x105c4444b in generateFromCLI (bun-debug)
        const reachable_files = try this.findReachableFiles();
                                                           ^
/Users/jarred/Code/bun/src/cli/build_command.zig:258:49: 0x105c4db4b in exec (bun-debug)
            break :brk (BundleV2.generateFromCLI(
                                                ^
/Users/jarred/Code/bun/src/cli.zig:1195:38: 0x105e22e37 in start (bun-debug)
                try BuildCommand.exec(ctx);
                                     ^
/Users/jarred/Code/bun/src/cli.zig:58:22: 0x105a34b43 in start__anon_3833 (bun-debug)
        Command.start(allocator, log) catch |err| {
                     ^
/Users/jarred/Code/bun/src/main.zig:38:22: 0x105a33343 in main (bun-debug)
    bun.CLI.Cli.start(bun.default_allocator, stdout, stderr, MainPanicHandler);
                     ^
/Users/jarred/zig/0.11.0-dev.4006+bf827d0b5/files/lib/std/start.zig:598:22: 0x105a33013 in main (bun-debug)
            root.main();
                     ^
???:?:?: 0x18cd2fe4f in ??? (???)
???:?:?: 0xb6517fffffffffff in ??? (???)
fish: Job 1, 'bun-debug build ./index.ts --co…' terminated by signal SIGABRT (Abort)

@azu
Copy link
Author

azu commented Jul 23, 2023

Thanks!

@QinZiWeiS
Copy link

I also encountered the same problem when introducing packages. How can I solve it?

@azu
Copy link
Author

azu commented Aug 1, 2023

This issue is resolved in Bun v0.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants