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

readline: clean up event listener in onNewListener #13266

Closed
wants to merge 3 commits into from
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
3 changes: 3 additions & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ function emitKeypressEvents(stream, iface) {
} else {
stream.on('newListener', onNewListener);
}
if (iface) {
iface.once('close', () => { stream.removeListener('data', onData); });
}
}

/**
Expand Down
6 changes: 4 additions & 2 deletions test/parallel/test-readline-set-raw-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ assert(!rawModeCalled);
assert(resumeCalled);
assert(!pauseCalled);

// One data listener for the keypress events.
assert.strictEqual(stream.listeners('data').length, 1);

// close() should call setRawMode(false)
expectedRawMode = false;
Expand All @@ -86,5 +88,5 @@ assert(!resumeCalled);
assert(pauseCalled);

assert.deepStrictEqual(stream.listeners('keypress'), []);
// one data listener for the keypress events.
assert.strictEqual(stream.listeners('data').length, 1);
// Data listener is removed once interface is closed.
assert.strictEqual(stream.listeners('data').length, 0);