holepunchto / hyperswarm

A distributed networking stack for connecting peers.
https://docs.holepunch.to
MIT License
1.06k stars 85 forks source link

All nodes are disconnected from the swarm when one node disconnects in V3 #93

Closed draeder closed 2 years ago

draeder commented 2 years ago

I have been experimenting with V3 on a local network. When running multiple instances on the same computer, I have no issues. However, when using two separate computers on the same local network, when I terminate the process on one of them, all hyperswarm nodes simultaneously lose connection with the following error:

events.js:377
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on NoiseSecretStream instance at:
    at WritableState.afterDestroy (/Users/danraeder/Documents/GitHub/hyperpeer/node_modules/streamx/index.js:442:19)
    at NoiseSecretStream._destroy (/Users/danraeder/Documents/GitHub/hyperpeer/node_modules/@hyperswarm/secret-stream/index.js:367:5)
    at WritableState.updateNonPrimary (/Users/danraeder/Documents/GitHub/hyperpeer/node_modules/streamx/index.js:189:16)
    at WritableState.update (/Users/danraeder/Documents/GitHub/hyperpeer/node_modules/streamx/index.js:174:70)
    at WritableState.updateWriteNT (/Users/danraeder/Documents/GitHub/hyperpeer/node_modules/streamx/index.js:482:8)
    at processTicksAndRejections (internal/process/task_queues.js:77:11) {
  errno: -54,
  code: 'ECONNRESET',
  syscall: 'read'
}

I attempted gracefully leaving the swarm with the following, to no avail:

    process.on('SIGINT', async function() {
        console.log("Caught interrupt signal");

        await swarm.leave(topic)

        process.exit()
    })

It is notable, though, this does not happen across different networks.

mafintosh commented 2 years ago

Hi 👋 you have to error handle the stream. That’s tcp telling the connection broke cause you closed on side of the swarm. To error handle listen for ‘error’ on the connection instance

draeder commented 2 years ago

Thanks! I didn't realize there were events I could listen to on the connection instance.