You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.
Calling conn.close() twice (without awaiting) will result in the second call hanging.
The problem is that if socket.end(cb) is called multiple times before the callback is executed, only the first callback will be executed.
Since the promise resolves in the callback, only the first conn.close() will resolve.
The socket.on('close', cb) callback will be triggered for both invocations, cancelling the timeout that provides the only other path to resolve the promise.
Here is a realistic-ish testcase showing how this may be an issue:
constLibp2p=require('libp2p')constTCP=require('libp2p-tcp')constMPLEX=require('libp2p-mplex')const{NOISE}=require('libp2p-noise')asyncfunctioncreateNode(){returnLibp2p.create({modules: {transport: [TCP],streamMuxer: [MPLEX],connEncryption: [NOISE],},addresses: {listen: ["/ip4/127.0.0.1/tcp/0"],},})}(asyncfunction(){// create nodesconstnodes=awaitPromise.all(Array.from({length: 2},createNode))// start nodesawaitPromise.all(nodes.map(n=>n.start()))// connect node 0 to node 1nodes[0].peerStore.addressBook.add(nodes[1].peerId,nodes[1].multiaddrs)awaitnodes[0].dial(nodes[1].peerId)// hangUp and stopnodes[0].hangUp(nodes[1].peerId)// not awaitedawaitPromise.all(nodes.map(n=>n.stop()))// will hang, never completeconsole.log('will hang, never complete')})()
The text was updated successfully, but these errors were encountered:
Calling
conn.close()
twice (without awaiting) will result in the second call hanging.The problem is that if
socket.end(cb)
is called multiple times before the callback is executed, only the first callback will be executed.Since the promise resolves in the callback, only the first
conn.close()
will resolve.The
socket.on('close', cb)
callback will be triggered for both invocations, cancelling the timeout that provides the only other path to resolve the promise.Here is a realistic-ish testcase showing how this may be an issue:
The text was updated successfully, but these errors were encountered: