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

events: remove error listener on signal abort #36969

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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