Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 50ea7aa

Browse files
authored
fix: do not send messages if the network is not running (#259)
Otherwise we can end up dialing a node during libp2p shut down
1 parent b805cab commit 50ea7aa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/network.js

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ class Network extends EventEmitter {
7979
* @param {AbortSignal} [options.signal]
8080
*/
8181
async * sendRequest (to, msg, options = {}) {
82+
if (!this._running) {
83+
return
84+
}
85+
8286
this._log('sending %s to %p', MESSAGE_TYPE_LOOKUP[msg.type], to)
8387

8488
try {
@@ -111,6 +115,10 @@ class Network extends EventEmitter {
111115
* @param {AbortSignal} [options.signal]
112116
*/
113117
async * sendMessage (to, msg, options = {}) {
118+
if (!this._running) {
119+
return
120+
}
121+
114122
this._log('sending %s to %p', MESSAGE_TYPE_LOOKUP[msg.type], to)
115123

116124
yield dialingPeerEvent({ peer: to })

0 commit comments

Comments
 (0)