Node: promises that don't fulfill hang repl with new top-level await

Created on 21 Nov 2017  路  9Comments  路  Source: nodejs/node

> await new Promise(() => {}); // or any "thenable"
// hangs

proposed solution is to add a timeout

  • Version: any with eeab7bc0688256247c47099a90c67741e6637e42
  • Platform: any
  • Subsystem: repl
repl

Most helpful comment

Chrome console doesn't "return" immediately, in that a returned value isn't shown. It just opens up the console to let one execute more code. This reflects on a fundamental difference between the Chrome console and Node.js REPL: while the Chrome console is asynchronous, the Node.js REPL is synchronous (not in its internals but in its operation).

I'm not sure if a timeout would be what users expect, especially since one can stop waiting for the promise by Ctrl+C. The REPL will return to the "Read" stage and the user can evaluate more expressions, but note, unlike synchronous methods Ctrl+C'ing does not halt the promise's execution.

All 9 comments

Do you have any suggestion for the expected behavior?

oops i forgot to say in the comment, i think a timeout should be added so things that won't resolve don't hang the repl

FWIW, Chrome console returns immediately in this case.

Chrome console doesn't "return" immediately, in that a returned value isn't shown. It just opens up the console to let one execute more code. This reflects on a fundamental difference between the Chrome console and Node.js REPL: while the Chrome console is asynchronous, the Node.js REPL is synchronous (not in its internals but in its operation).

I'm not sure if a timeout would be what users expect, especially since one can stop waiting for the promise by Ctrl+C. The REPL will return to the "Read" stage and the user can evaluate more expressions, but note, unlike synchronous methods Ctrl+C'ing does not halt the promise's execution.

Maybe not pause the prompt and log out the result when it is resolved/avalible.

i'm working on a system where awaits that run longer than a tick get an "await id" and then when they resolve will be output with that id
```js

await Promise.resolve(5);
5
await new Promise(r => setTimeout(() => r('done'), 1000));
AWAIT01 (pending)
5 + 5
10
AWAIT01 => 'done'

Using require('repl') for the actual custom repl implementation will hard hang node on un-fulfilling promise, (NO reaction to SIGINT, only SIGTERM kills it).

@pkit You can specify the breakEvalOnSigint option of repl.start to allow SIGINT detection.

@TimothyGu I already have it set, top level await will hang anyway

Was this page helpful?
0 / 5 - 0 ratings

Related issues

addaleax picture addaleax  路  146Comments

yury-s picture yury-s  路  89Comments

mikeal picture mikeal  路  90Comments

TazmanianDI picture TazmanianDI  路  127Comments

benjamingr picture benjamingr  路  135Comments