Skip to content

[Bug] Remove the incorrect event listener.#36522

@iamnivekx

Description

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

What steps will reproduce the bug?

constEventEmitter=require('events');constee=newEventEmitter();// const symbol = Symbol('listener');constsymbol='listener';constfn2=function(...args){console.log('Call fn2', ...args)};constfn=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 fnconsole.log('1. remove fn2')ee.removeListener('one',fn2);// fn is removed, expect remove the fn2 ee.emit('one');// Prints: // Call fn2console.log('2. remove fn2 again')ee.removeListener('one',fn2)// fn2 is removedee.emit('one')// Prints: // Call fn2console.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?

Callfn2Callfn1.removefn2Callfn2.removefn2againCallfn3.removefn2againCallfn

What do you see instead?

Callfn2Callfn1.removefn2Callfn22.removefn2again3.removefn2again

Additional information

Replace the listener attribute of event listener with symbol

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventsIssues and PRs related to the events subsystem / EventEmitter.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions