Skip to content

Commit 7243277

Browse files
committed
Check if channel has subscribers before call unsubscribe (#2770)
1 parent 1465e46 commit 7243277

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/dd-trace/src/log/writer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ function withNoop (fn) {
2323
}
2424

2525
function unsubscribeAll () {
26-
debugChannel.unsubscribe(onDebug)
27-
infoChannel.unsubscribe(onInfo)
28-
warnChannel.unsubscribe(onWarn)
29-
errorChannel.unsubscribe(onError)
26+
if (debugChannel.hasSubscribers) {
27+
debugChannel.unsubscribe(onDebug)
28+
}
29+
if (infoChannel.hasSubscribers) {
30+
infoChannel.unsubscribe(onInfo)
31+
}
32+
if (warnChannel.hasSubscribers) {
33+
warnChannel.unsubscribe(onWarn)
34+
}
35+
if (errorChannel.hasSubscribers) {
36+
errorChannel.unsubscribe(onError)
37+
}
3038
}
3139

3240
function toggleSubscription (enable) {

0 commit comments

Comments
 (0)