Skip to content

Commit 6fd28e0

Browse files
committed
fix tracer unsubscribing from externally active channel
1 parent 84458ef commit 6fd28e0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

  • packages/diagnostics_channel/src

packages/diagnostics_channel/src/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const {
4+
Channel,
45
channel
56
} = require('diagnostics_channel') // eslint-disable-line n/no-restricted-require
67

@@ -20,9 +21,11 @@ if (major === '19' && minor === '9') {
2021

2122
if (!channels.has(ch)) {
2223
const subscribe = ch.subscribe
24+
const unsubscribe = ch.unsubscribe
2325

2426
ch.subscribe = function () {
2527
delete ch.subscribe
28+
delete ch.unsubscribe
2629

2730
const result = subscribe.apply(this, arguments)
2831

@@ -31,6 +34,19 @@ if (major === '19' && minor === '9') {
3134
return result
3235
}
3336

37+
if (ch.unsubscribe === Channel.prototype.unsubscribe) {
38+
// Needed because another subscriber could have subscribed to something
39+
// that we unsubscribe to before the library is loaded.
40+
ch.unsubscribe = function () {
41+
delete ch.subscribe
42+
delete ch.unsubscribe
43+
44+
this.subscribe(() => {}) // Keep it active forever.
45+
46+
return unsubscribe.apply(this, arguments)
47+
}
48+
}
49+
3450
channels.add(ch)
3551
}
3652

0 commit comments

Comments
 (0)