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

CallbackJob prevents VM to exit when result of callback is an unresolved promise #11377

Closed
zawodskoj opened this issue May 26, 2024 · 0 comments · Fixed by #11379
Closed

CallbackJob prevents VM to exit when result of callback is an unresolved promise #11377

zawodskoj opened this issue May 26, 2024 · 0 comments · Fixed by #11379
Labels
bug Something isn't working

Comments

@zawodskoj
Copy link
Contributor

What version of Bun is running?

1.1.10+5102a9443

What platform is your computer?

Any platform, reproduces everywhere

What steps can reproduce the bug?

This simple code will result in frozen process

setTimeout(() => new Promise(() => 0), 0);

What is the expected behavior?

Process exits immediately after setTimeout (which aligns with Node behavior)

What do you see instead?

Process is stuck. For whatever reason if CallbackJob sees promise, it will subscribe and wait until it succeeds, and this is not always the case.

result.then(globalThis, this, CallbackJob__onResolve, CallbackJob__onReject);

Potential solution is to deinit CallbackJob regardless of promise status

Additional information

This bug affects Worker.terminate() - terminate() returns promise which will never complete if Worker is already terminated. #9998 is affected by this bug.

The fact that Worker.terminate() is not fulfilling promise is separate issue. Node fulfills promise every time, but with undefined status code in this case. In attempt to fix original issue's problem I fixed that in #11376

There's also (absolutely irrelevant to this issue, but still notable) difference in status codes - Worker.terminate() yields status code 0 when thread is actually terminated, whereas Node returns 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

Successfully merging a pull request may close this issue.

1 participant