node icon indicating copy to clipboard operation
node copied to clipboard

Internal Assertion in `AbortSignal`

Open redyetidev opened this issue 5 months ago • 0 comments

I am working on updating the Web Platform Tests in #54468, but ran into an issue occuring with AbortSignal. I narrowed down the issue to a minimal reproduction, with leads to an ERR_INTERNAL_ASSERTION:

const controller = new AbortController();
const signal1 = AbortSignal.any([controller.signal]);

controller.signal.addEventListener('abort', () => {
    AbortSignal.any([signal1]);
})

controller.abort();
node:internal/event_target:1090
  process.nextTick(() => { throw err; });
                           ^

Error [ERR_INTERNAL_ASSERTION]: This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at assert (node:internal/assert:14:11)
    at AbortSignal.any (node:internal/abort_controller:253:11)
    at AbortSignal.<anonymous> (/repro.js:5:17)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:816:20)
    at AbortSignal.dispatchEvent (node:internal/event_target:751:26)
    at abortSignal (node:internal/abort_controller:374:10)
    at AbortController.abort (node:internal/abort_controller:396:5)
    at Object.<anonymous> (/repro.js:8:12)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1691:10) {
  code: 'ERR_INTERNAL_ASSERTION'
}

Node.js v22.7.0

The failed assertion is https://github.com/nodejs/node/blob/885692a34f582c99d74430ba351879431738e43a/lib/internal/abort_controller.js#L253


It seems to me that Node.js's current behavior is to fail the assertion when a signal has already aborted, however the WPT's expected behavior is that "Dependent signals for AbortSignal.any() are marked aborted before abort events fire": https://github.com/web-platform-tests/wpt/blob/e78446e34a1921371658a5df08c71d83f50a2a2f/dom/abort/resources/abort-signal-any-tests.js#L193

redyetidev avatar Aug 28 '24 00:08 redyetidev