bun icon indicating copy to clipboard operation
bun copied to clipboard

Segmentation fault in Bun Shell

Open 7flash opened this issue 1 year ago • 5 comments

How can we reproduce the crash?

No response

Relevant log output

Bun v1.1.20 (ae194892) macOS Silicon
macOS v13.3

Features: jsc Bun.stderr(12) Bun.stdout(12) shell(40) spawn(15) 
Builtins: "bun:main" 
Elapsed: 33446ms | User: 28ms | Sys: 154ms
RSS: 11.89MB | Peak: 25.15MB | Commit: 1.07GB | Faults: 2868

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

Stack Trace (bun.report)

Bun v1.1.20 (ae19489) on macos aarch64 [AutoCommand]

Segmentation fault at address 0x00000008

  • 2 unknown/js code
  • src.shell.interpreter.StatePtrUnion
  • src.shell.interpreter.Interpreter.Expansion.next
  • src.shell.interpreter.StatePtrUnion
  • src.shell.interpreter.Interpreter.Expansion.next
  • src.shell.interpreter.StatePtrUnion
  • src.shell.interpreter.Interpreter.Expansion.next
  • src.shell.interpreter.StatePtrUnion
  • src.shell.interpreter.Interpreter.Script.start

7flash avatar Sep 02 '24 02:09 7flash

@7flash, the latest version of Bun is v1.1.26, but this crash was reported on Bun v1.1.20.

Are you able to reproduce this crash on the latest version of Bun?

bun upgrade

github-actions[bot] avatar Sep 02 '24 02:09 github-actions[bot]

@7flash can you paste the last shell script that was run?

Jarred-Sumner avatar Sep 02 '24 02:09 Jarred-Sumner

@7flash can you paste the last shell script that was run?

I have this program running continuously for days and it looks something like this:

first.sh

while IFS= read -r it; do #iterate over things
    bun second.ts "${it}" > answer.txt
    vim answer.txt
done < "$things"

second.ts

const it = await Bun.password.hash(process.argv[2])
const answer = await $`python3 third.py "${it}"`
console.log(answer)

third.py

it = sys.argv[1]
answer = generate(it)
print(answer)

Its just a minimal reproduction to demonstrate the flow of my program, which you might find unconventional so let me explain:

In my terminal I am running first.sh which runs second.ts which runs third.py

The reason I am running first.sh because its the only way I can completely pause my program while I am reviewing answer.txt and fixing second/third scripts, in the same terminal window, its really special experience for me being to be able to do it in my favourite editor vim/helix instead of opening some web ui. I hope its not too crazy, but please let me know if there are any drawbacks i must be aware when building apps following this approach.

Anyway, the moment something went wrong, is most probably when I tried to airdrop some large files into my macbook where the script was running, and that might have caused the memory issue, when I noticed the script has stopped running, while being at stage of waiting response from third.py.

I am curious about what can I understand from this error message, specifically what following number mean?

shell(40) User: 28ms Commit: 1.07GB | Faults: 2868

7flash avatar Sep 04 '24 10:09 7flash

Btw I've found something in docs which gives me hope it might be possible to switch from running script to editing file in a terminal? But it doesn't work, it's not doing anything when I run this script.

Bun.openInEditor(import.meta.url, { editor: "hx", });

7flash avatar Sep 11 '24 16:09 7flash

I was also getting segfault 0x8 .

To anybody else experiencing this I was able to get around it by switching my Bun.$ calls with Bun.Spawn

pauldvu avatar Dec 18 '24 05:12 pauldvu

We've fixed a lot of reliability issues in the shell since the time this was reported. Please let us know if you continue to run into this.

Jarred-Sumner avatar Sep 07 '25 00:09 Jarred-Sumner