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

[Bug] Remove the incorrect event listener. #36522

Open
peng-huang-ch opened this issue Dec 15, 2020 · 3 comments
Open

[Bug] Remove the incorrect event listener. #36522

peng-huang-ch opened this issue Dec 15, 2020 · 3 comments
Labels
events Issues and PRs related to the events subsystem / EventEmitter.

Comments

@peng-huang-ch
Copy link

  • Version: v15.4.0
  • Platform: MacOS V10.15.7
  • Subsystem: lib/events.js

What steps will reproduce the bug?

const EventEmitter = require('events');
const ee = new EventEmitter();
// const symbol = Symbol('listener');
const symbol = 'listener';

const fn2 = function(...args) {
    console.log('Call fn2', ...args)
};

const fn = function (...args) {
    console.log('Call fn', ...args);
};

fn[symbol] = fn2;

ee.on('one', fn2)
ee.on('one', fn);
ee.emit('one');
// Prints: 
//    Call fn2
//    Call fn

console.log('1. remove fn2')
ee.removeListener('one', fn2); // fn is removed, expect remove the fn2 
ee.emit('one');
// Prints: 
//    Call fn2

console.log('2. remove fn2 again')
ee.removeListener('one', fn2) // fn2 is removed
ee.emit('one')
// Prints: 
//    Call fn2

console.log('3. remove fn2 again');
ee.emit('one')

How often does it reproduce? Is there a required condition?

Occurs every time.

What is the expected behavior?

Call fn2
Call fn
1. remove fn2
Call fn
2. remove fn2 again
Call fn
3. remove fn2 again
Call fn

What do you see instead?

Call fn2
Call fn
1. remove fn2
Call fn2
2. remove fn2 again
3. remove fn2 again

Additional information

Replace the listener attribute of event listener with symbol

@PoojaDurgad PoojaDurgad added the events Issues and PRs related to the events subsystem / EventEmitter. label Dec 16, 2020
@yashLadha
Copy link
Contributor

Would like to solve this issue, seems userland is updating the attributes needed by the interface.

@peng-huang-ch
Copy link
Author

I have created a pr #36558, could you help to review it, THX.

@yashLadha
Copy link
Contributor

Sure @peng-huang-cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
events Issues and PRs related to the events subsystem / EventEmitter.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants