Skip to content

End handlers not being removed after next resolve #5

@AKST

Description

@AKST

In the notReadable state it's listening for either the end or read callback to finish, unfortunately if the read callback fires it doesn't clean up the end callback. And after 11 calls to next there are 10 event listeners for the end callback.

I know in my node version I get warned about possible memory leaks.


Suggestion

The existing logic here

await Promise.race([this._untilReadable(), this._untilEnd()]);

Could possibly changed to this

const { promise: readPromise, cleanup: cleanRead } = this._untilReadable();
const { promise: endPromise,  cleanup: cleanEnd } = this._untilEnd();
await Promise.race([readPromise, endPromise]);
cleanRead();
cleanEnd();

The cleanUp callbacks will unhook any dangling event listeners

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions