Skip to content

Commit

Permalink
events: remove error listener on signal abort
Browse files Browse the repository at this point in the history
Fixes: #36949

PR-URL: #36969
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
Lxxyx authored and ruyadorno committed Jan 25, 2021
1 parent d2d9ad7 commit dc596d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ async function once(emitter, name, options = {}) {
}
function abortListener() {
eventTargetAgnosticRemoveListener(emitter, name, resolver);
eventTargetAgnosticRemoveListener(emitter, 'error', resolver);
eventTargetAgnosticRemoveListener(emitter, 'error', errorListener);
reject(lazyDOMException('The operation was aborted', 'AbortError'));
}
if (signal != null) {
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-events-once.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,19 @@ async function abortSignalAfterEvent() {
await once(ee, 'foo', { signal: ac.signal });
}

async function abortSignalRemoveListener() {
const ee = new EventEmitter();
const ac = new AbortController();

try {
process.nextTick(() => ac.abort());
await once(ee, 'test', { signal: ac.signal });
} catch {
strictEqual(ee.listeners('test').length, 0);
strictEqual(ee.listeners('error').length, 0);
}
}

async function eventTargetAbortSignalBefore() {
const et = new EventTarget();
const ac = new AbortController();
Expand Down Expand Up @@ -218,6 +231,7 @@ Promise.all([
abortSignalBefore(),
abortSignalAfter(),
abortSignalAfterEvent(),
abortSignalRemoveListener(),
eventTargetAbortSignalBefore(),
eventTargetAbortSignalAfter(),
eventTargetAbortSignalAfterEvent(),
Expand Down

0 comments on commit dc596d0

Please sign in to comment.