GeezerVison is showing github.com — diagnostics_channel: fix last subscriber removal · nodejs/node@114e088
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/diagnostics_channel.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -136,7 +136,7 @@ class ActiveChannel { |
136 | 136 | } |
137 | 137 |
|
138 | 138 | publish(data) { |
139 | | - for (let i = 0; i < this._subscribers.length; i++) { |
| 139 | + for (let i = 0; i < (this._subscribers?.length || 0); i++) { |
140 | 140 | try { |
141 | 141 | const onMessage = this._subscribers[i]; |
142 | 142 | onMessage(data, this.name); |
|
Collapse file
Copy file name to clipboard +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const dc = require('node:diagnostics_channel'); |
| 5 | + |
| 6 | +const channel_name = 'test:channel'; |
| 7 | +const published_data = 'some message'; |
| 8 | + |
| 9 | +const onMessageHandler = common.mustCall(() => dc.unsubscribe(channel_name, onMessageHandler)); |
| 10 | + |
| 11 | +dc.subscribe(channel_name, onMessageHandler); |
| 12 | + |
| 13 | +// This must not throw. |
| 14 | +dc.channel(channel_name).publish(published_data); |