latysheff / node-sctp

SCTP userspace sockets for Node.js
MIT License
59 stars 10 forks source link

Uncaught Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running #16

Closed ibc closed 4 years ago

ibc commented 4 years ago

Using SCTP over UDP and this is happening eventually when closing the SCTP endpoint. It produces an uncaught error event so it's terminating the whole Node process (this is 200% critical for me):

Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
    at healthCheck (dgram.js:605:11)
    at Socket.send (dgram.js:399:3)
    at UDPTransport.sendPacket (/Users/xxx/src/some-project/node_modules/sctp/lib/transport.js:455:19)
    at Endpoint._sendPacket (/Users/xxx/src/some-project/node_modules/sctp/lib/endpoint.js:448:20)
    at Association._sendPacket (/Users/xxx/src/some-project/node_modules/sctp/lib/association.js:1327:19)
    at processedQueue.forEach (/Users/xxx/src/some-project/node_modules/sctp/lib/association.js:1485:18)
    at Array.forEach (<anonymous>)
    at Association._bundle (/Users/xxx/src/some-project/node_modules/sctp/lib/association.js:1395:20)
    at Timeout.setTimeout (/Users/xxx/src/some-project/node_modules/sctp/lib/association.js:926:14)
    at ontimeout (timers.js:436:11)
ibc commented 4 years ago

By looking at the trace it happens in a non controlled timeout in association.js line 925:

setTimeout(() => {
   this._bundle()
})

It may happen that the association is closed/ended while the callback given to setTimeout() is not yet executed, so it will be called in wrong state. Then it will invoke UDP socket.send() without any try & catch in transport.js:455 and thus produce an uncaught error event that, by Node design, terminates the entire process, which is terrible in a server given that the application can not avoid that.

latysheff commented 4 years ago

Fixed with try/catch until module refactoring.