Skip to content

[Bug] Remove the incorrect event listener. #36522

Description

@nivek3
  • 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

Activity

  1. added
    eventsIssues and PRs related to EventEmitter and the events module.
    on Dec 16, 2020
  2. yashLadha commented on Dec 18, 2020

    @yashLadha
    Contributor

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

  3. nivek3 commented on Dec 18, 2020

    @nivek3
    Author

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

  4. yashLadha commented on Dec 18, 2020

    @yashLadha
    Contributor

    Sure @peng-huang-cc

  5. github-actions commented on Jun 27, 2026

    @github-actions
    Contributor

    This issue has been marked as stale due to 210 days of inactivity.
    It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

  6. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 27, 2026
  7. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

    This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
    If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventsIssues and PRs related to EventEmitter and the events module.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions