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

Conversation

gibfahn
Copy link
Member

@gibfahn gibfahn commented May 28, 2017

If this is a bug, then let's just fix it.

Refs: #9447 (comment)

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

readline

@nodejs-github-bot nodejs-github-bot added the readline Issues and PRs related to the built-in readline module. label May 28, 2017
@gibfahn
Copy link
Member Author

gibfahn commented May 28, 2017

cc/ @STRML

@princejwesley LMK if you're okay with this landing under your name (as it's your code!)

@gibfahn
Copy link
Member Author

gibfahn commented May 28, 2017

Moved the check out of the function and handled iface being undefined, to avoid this error:

Cannot read property 'once' of undefined
=== release test-readline-emit-keypress-events ===                             
Path: parallel/test-readline-emit-keypress-events
readline.js:1033
      iface.once('close', () => { stream.removeListener('data', onData); });
           ^

TypeError: Cannot read property 'once' of undefined
    at PassThrough.onNewListener (readline.js:1033:12)
    at emitTwo (events.js:125:13)
    at PassThrough.emit (events.js:213:7)
    at _addListener (events.js:248:14)
    at PassThrough.addListener (events.js:298:10)
    at PassThrough.Readable.on (_stream_readable.js:759:35)
    at Object.<anonymous> (/Users/gib/wrk/com/node/test/parallel/test-readline-emit-keypress-events.js:16:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
Command: out/Release/node /Users/gib/wrk/com/node/test/parallel/test-readline-emit-keypress-events.js

This now fails test-readline-set-raw-mode.js#L90 with:

=== release test-readline-set-raw-mode ===                        
Path: parallel/test-readline-set-raw-mode
assert.js:60
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: 0 === 1
    at Object.<anonymous> (/Users/gib/wrk/com/node/test/parallel/test-readline-set-raw-mode.js:90:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:144:16)
    at bootstrap_node.js:561:3
Command: out/Release/node /Users/gib/wrk/com/node/test/parallel/test-readline-set-raw-mode.js
[01:42|% 100|+ 1563|-   2]: Done 

That assertion was added in nodejs/node-v0.x-archive#3757, which fixed nodejs/node-v0.x-archive#3756.

@gibfahn
Copy link
Member Author

gibfahn commented May 28, 2017

Changed the test to assert that there is 1 listener until you close, and 0 listeners afterwards. Not sure if that's the intended behaviour.

Also not sure whether this would be semver-major or semver-patch, I think this is just a bug, but 🤷‍♂️ .

CI: https://ci.nodejs.org/job/node-test-commit/10208/

jasnell pushed a commit that referenced this pull request Jun 1, 2017
Once the Readline interface is closed, the 'data' event listener should
be removed.

PR-URL: #13266
Ref: #9447 (comment)
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell
Copy link
Member

jasnell commented Jun 1, 2017

Landed in 7d53aba

@jasnell jasnell closed this Jun 1, 2017
@gibfahn gibfahn deleted the readline-listener branch June 2, 2017 08:22
jasnell pushed a commit that referenced this pull request Jun 5, 2017
Once the Readline interface is closed, the 'data' event listener should
be removed.

PR-URL: #13266
Ref: #9447 (comment)
Reviewed-By: James M Snell <jasnell@gmail.com>
@jasnell jasnell mentioned this pull request Jun 5, 2017
@addaleax
Copy link
Member

addaleax commented Jun 8, 2017

@gibfahn This breaks real-world applications: #13557

We should probably revert for now?

@jasnell
Copy link
Member

jasnell commented Jun 8, 2017

I'm good with reverting but it would definitely be good to understand why it breaks things because the change is obstensibly correct ... There should not be any more data events after the close event, and there shouldn't be reason to keep the listener there. Preferably the reason for the break can be fixed so that this commit can be reapplied.

addaleax added a commit to addaleax/node that referenced this pull request Jun 8, 2017
@gibfahn
Copy link
Member Author

gibfahn commented Jun 8, 2017

I'm good with reverting but it would definitely be good to understand why it breaks things...

For anyone reading this issue (possibly in the distant future 🛰 ), @addaleax has since answered this in #13560 (comment):

The interface instance passed to emitKeypressEvents() is explicitly not for decoder lifetime control; it is just used to toggle tab completion on it. We provide emitKeypressEvents() as a standalone method as well, which should work on its own exactly as documented (i.e. independently of any readline interfaces by default).

addaleax added a commit that referenced this pull request Jun 10, 2017
This reverts commit 81ddeb9.

Ref: #13266
PR-URL: #13560
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
addaleax added a commit that referenced this pull request Jun 10, 2017
This reverts commit 81ddeb9.

Ref: #13266
PR-URL: #13560
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins
Copy link
Contributor

I'm marking this as dont-land as it appears to be reverted. Let me know if this is a mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants