You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Promise.prototype.finally() never settles when the promise resolves after .finally() is attached #596
A promise returned by .finally() on a workerpool Promise never settles, either resolved or rejected, if the original promise settles after .finally() was called. The callback passed to .finally() runs, but awaiting the result hangs forever. Every promise returned by pool.exec() is in that state, so await pool.exec(...).finally(...) never continues.
now: finally callback ran
now settled with 7
later: finally callback ran
later settled with 42 is never logged. Node then exits with the await still pending, because nothing will ever settle it. Rejecting instead of resolving behaves the same way.
When me settles, _resolve runs _onSuccess.forEach(...), which calls final synchronously. Inside it, the synchronous chain reaches .then(() => me), and _then calls me.then(resolve, reject). At that point me's _process has not yet been replaced with the "already settled" version. That replacement only happens after the forEach. So the callback is pushed onto _onSuccess, and forEach never visits it because it stops at the array's original length. The promise returned by finally is never resolved.
In the already-settled case (now above), _process has already been replaced, so the callback is called immediately and everything works.
Possible fixes
In _resolve / _reject, swap _process (and the _resolve / _reject no-ops) before running the queued callbacks, so a re-entrant then on the same promise runs immediately.
Activity