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

Viewed 1338

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?

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 its exiting abnormally and gives a 13 exit code.

Related