Skip to content

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node emits MaxListenersExceededWarning with v9.0.0

3 participants