Skip to content

Commit ebec8d6

Browse files
authored
fix bound emitters leaking when trying to remove all listeners (#1260)
1 parent a431ac2 commit ebec8d6

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/dd-trace/src/scope/base.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function wrapRemoveListener (removeListener) {
188188

189189
listeners.delete(listener)
190190

191-
return removeListener.call(this, eventName, listener)
191+
return removeListener.apply(this, arguments)
192192
}
193193
}
194194

@@ -202,7 +202,7 @@ function wrapRemoveAllListeners (removeAllListeners) {
202202
}
203203
}
204204

205-
return removeAllListeners.call(this, eventName)
205+
return removeAllListeners.apply(this, arguments)
206206
}
207207
}
208208

packages/dd-trace/test/scope/test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,43 @@ module.exports = factory => {
300300

301301
expect(spy).to.not.have.been.called
302302
})
303+
304+
it('should remove all listeners of a type', () => {
305+
const spy = sinon.spy()
306+
const spy2 = sinon.spy()
307+
308+
scope.bind(emitter)
309+
310+
scope.activate(span, () => {
311+
emitter.once('test', spy)
312+
emitter.once('test', spy2)
313+
emitter.removeAllListeners('test')
314+
})
315+
316+
emitter.emit('test')
317+
318+
expect(spy).to.not.have.been.called
319+
expect(spy2).to.not.have.been.called
320+
})
321+
322+
it('should remove all listeners', () => {
323+
const spy = sinon.spy()
324+
const spy2 = sinon.spy()
325+
326+
scope.bind(emitter)
327+
328+
scope.activate(span, () => {
329+
emitter.once('test', spy)
330+
emitter.once('test2', spy2)
331+
emitter.removeAllListeners()
332+
})
333+
334+
emitter.emit('test')
335+
emitter.emit('test2')
336+
337+
expect(spy).to.not.have.been.called
338+
expect(spy2).to.not.have.been.called
339+
})
303340
})
304341

305342
describe('with an unsupported target', () => {

0 commit comments

Comments
 (0)