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 exits early, with no visible cause. #9117

Open
adrianbrowning opened this issue Feb 26, 2024 · 4 comments
Open

bun exits early, with no visible cause. #9117

adrianbrowning opened this issue Feb 26, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@adrianbrowning
Copy link

What version of Bun is running?

1.0.29+a146856d1

What platform is your computer?

Darwin 23.3.0 x86_64 i386

What steps can reproduce the bug?

Here is a small repo that can reproduce the issue. https://github.com/adrianbrowning/mvt-bun-prisma.

  1. Clone repo
  2. bun i, will also create the db.db file
  3. Run bun no-brk/ bun just-inspect and see that the output stop
  4. Run bun with-brk. Brin up the debugger and see that the output continues.

What is the expected behavior?

Running bun with-brk gives:

$ bun --inspect-brk run src/index.ts
--------------------- Bun Inspector ---------------------
Listening:
  ws://localhost:6499/ur9fw7be6j
Inspect in browser:
  https://debug.bun.sh/#localhost:6499/ur9fw7be6j
--------------------- Bun Inspector ---------------------
Clearing db start
Clearing db done
run start
{
  id: 1,
  email: "[email protected]",
  name: "Alice",
}
run done
closing db start
closing db done
Ended: Mon Feb 26 2024 11:48:32 GMT+0000 (Greenwich Mean Time), took 0.07280554100000063 seconds

What do you see instead?

Running bun no-brk OR bun just-inspect both show the following:

$ bun run src/index.ts
Clearing db start
$ bun run --inspect src/index.ts
--------------------- Bun Inspector ---------------------
Listening:
  ws://localhost:6499/80uc9qwbpz6
Inspect in browser:
  https://debug.bun.sh/#localhost:6499/80uc9qwbpz6
--------------------- Bun Inspector ---------------------
Clearing db start

Additional information

Might also relate to:
#8629

@adrianbrowning adrianbrowning added the bug Something isn't working label Feb 26, 2024
@Jarred-Sumner
Copy link
Collaborator

Try moving this to the bottom of the file and prepending await:

await clearDB()
  .then(run)
  .catch(e => console.error(e))
  .then(closeDb)
  .then(_=>{
    console.log(`Ended: ${new Date}, took ${humanizeDuration(performance.now() - start)}`);
    return null;
  })
  .catch(e => {throw e;});

@adrianbrowning
Copy link
Author

Thanks @Jarred-Sumner , just adding the await did the trick.
I hadn't thought to do that, as the code works in NodeJS land.

Seems odd that you would need to prepend the await as it is a valid promise chain, is it not?

@paperclover
Copy link
Member

what is happening is somewhere in this line of async work, bun does not realize there are active operations happening, so it quits thinking the async work is done.

the await prevents the main file from finish running before that.

this is still a bug its just not immediatly clear what part of the async chain is forgetting to keep the event loop alive.

@9Morello
Copy link

9Morello commented Mar 1, 2024

@paperdave seems similar to this other issue , where adding an await caused the program to work as expected.

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

4 participants