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

Spurious 'unhandledRejection' events #320

Closed
jrvidal opened this issue Feb 21, 2021 · 1 comment · Fixed by #328
Closed

Spurious 'unhandledRejection' events #320

jrvidal opened this issue Feb 21, 2021 · 1 comment · Fixed by #328

Comments

@jrvidal
Copy link

jrvidal commented Feb 21, 2021

IxJS version: 4.2.0

Code to reproduce:

const { batch, withAbort } = require("ix/asynciterable/operators");
const { AsyncSink } = require("ix/asynciterable");

process.on("unhandledRejection", (reason, promise) => {
  console.log("Unhandled Rejection at:", promise, "reason:", reason);
});

(async () => {
  const sink = new AsyncSink();

  let it = batch()(sink)[Symbol.asyncIterator]();

  const next = it.next();

  sink.error(new Error("sink error"));

  try {
    await next;
    throw new Error("Unexpected");
  } catch (e) {
    console.log("did throw");
  }
})().catch((e) => console.log("error handled", e));

Expected behavior:
No "Unhandled rejection" message should be printed.

Actual behavior:
An "Unhandled rejection" error gets printed:

did throw
Unhandled Rejection at: Promise {
  <rejected> Error: sink error
      at /testcase/index.js:15:14
      at Object.<anonymous> (/testcase/index.js:23:3)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
      at internal/main/run_main_module.js:17:47
} reason: Error: sink error
    at /testcase/index.js:15:14
    at Object.<anonymous> (/testcase/index.js:23:3)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Additional information:

I think the root cause is here, where a rejected promise gets created, but not immediately returned to some caller. The fix is simple, but I'm having a hard time reproducing it in a test.

@trxcllnt
Copy link
Member

trxcllnt commented Jun 9, 2021

Fix released in ix@4.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants