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

Awaiting never-resolved promise makes Deno hang & hot spin. #7945

Closed
piscisaureus opened this issue Oct 12, 2020 · 4 comments · Fixed by #7946
Closed

Awaiting never-resolved promise makes Deno hang & hot spin. #7945

piscisaureus opened this issue Oct 12, 2020 · 4 comments · Fixed by #7946
Labels
bug Something isn't working correctly cli related to cli/ dir

Comments

@piscisaureus
Copy link
Member

piscisaureus commented Oct 12, 2020

deno run this.

// x.js
await new Promise(() => {});

It spins because there is nothing happening any more, and tokio can't block the event loop for us (there's nothing to poll).

Deno should either:

  • exit
  • throw an exception similar to UncaughtException. Maybe AwaitNeverException or something?
@bartlomieju
Copy link
Member

I've tried this in latest node and it exits silently with exit code 13.

~/dev/deno
▶ node --version
v14.13.1

~/dev/deno
▶ node foo.mjs

~/dev/deno
▶ echo $?
13

@ry ry added bug Something isn't working correctly cli related to cli/ dir labels Oct 12, 2020
@ghost
Copy link

ghost commented Oct 12, 2020

How would Deno know that the promise will never resolve? Shouldn't it just keep the process alive?

I would check how browsers handle this, except... they don't have top-level await yet.

@lucacasonato
Copy link
Member

How would Deno know that the promise will never resolve? Shouldn't it just keep the process alive?

Because no IO ops or timers are going on anymore (ie no timers scheduled to fire, no file reading going on). There is nothing the event loop is waiting for to complete. That means there is no way JS execution will be resumed ever (because there is nothing to trigger that), so the promise can never be resolved.

@ghost
Copy link

ghost commented Oct 12, 2020

Because no IO ops or timers are going on anymore (ie no timers scheduled to fire, no file reading going on). There is nothing the event loop is waiting for to complete. That means there is no way JS execution will be resumed ever (because there is nothing to trigger that), so the promise can never be resolved.

Ah yes, it can be determined if the event loop is depleted, and no code is being executed. Guess then it should be safe to error or exit.
Does the ECMAScript standard define what to do about never resolving promises in TLA, or just never resolving promises in general, and any specific conditions that must be met to mark it as never resolving?

Also, what about situations like:

const temp = () => {};

self.addEventListener(
    "message",
    temp
);

await new Promise( temp );

Can it be safely determined that the promise will not resolve, as there are still events being listened to?

Also, just tested on an older Deno (1.1.0) and it just silently exits with exit code 0. Does this mean that this changed over time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants