Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Node exiting with exit code 13, rather than hanging?

A file deadlock.mjs with this in it:

await new Promise(function(resolve) {});

will run and immediately end giving an exit code of 13. I would've expected this program to hang forever.

await new Promise(function(resolve) {resolve()});

unsurprisingly ends immediately and gives a 0 exit code.

Why doesn't the first program deadlock? And what is the significance of exit code 13?

like image 296
johncs Avatar asked Jan 01 '26 08:01

johncs


1 Answers

Node isn't deadlocking because it's noticing that it's not waiting on anything. Here's a great explanation of how it notices that. But because you've used a top-level await here, Node knows that it's exiting abnormally and gives a 13 exit code:

13 Unfinished Top-Level Await: await was used outside of a function in the top-level code, but the passed Promise never resolved.

https://nodejs.org/api/process.html#exit-codes

like image 190
2 revs, 2 users 71%Nick McCurdy Avatar answered Jan 04 '26 01:01

2 revs, 2 users 71%Nick McCurdy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!