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

Don't set up more than 1 abort signal listener #503

Merged
merged 1 commit into from
Sep 12, 2024
Merged

Conversation

gustavohenke
Copy link
Member

🤦 Rxjs' fromEvent creates a new listener on every subscription, but this is a bit hidden because the abort signal isn't subscribed to directly:

const abort =
abortSignal &&
Rx.fromEvent(abortSignal, 'abort', { once: true }).pipe(
// The abort signal must happen before commands are killed, otherwise new commands
// might spawn. Because of this, it's not be possible to capture the close events
// without an immediate delay
delay(0, this.scheduler),
map(() => undefined),
);
const closeStreams = commands.map((command) =>
abort
? // Commands that have been started must close.
Rx.race(command.close, abort.pipe(filter(() => command.state === 'stopped')))

Sounds like just sharing the underlying source observable is enough.

Fixes #502

@coveralls
Copy link

Coverage Status

coverage: 98.263%. remained the same
when pulling 74cc2f2 on abortsignal-leak
into a7a5894 on main.

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

Successfully merging this pull request may close these issues.

Node emits MaxListenersExceededWarning with v9.0.0
2 participants