latysheff / node-sctp

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

How to really close sctpSocket #11

Closed ibc closed 5 years ago

ibc commented 5 years ago

By creating some unit tests (SCTP over plain UDP, in both UDP unconnected and connected mode in Node >= 12), I'm realizing that once sctpSocket = sctp.connect() is called, the test script cannot exit because, somehow, some handler remains active.

I'm closing the udpSocket I provide sctp.connect() with, and also trying to "terminate" the sctpSocket by calling end() on it when the test ends, also destroy(). Nothing works. It looks like if some internal timer within node-sctp (probably stuff doing the INIT ACK exchange) remains working inside and it's not terminated.

Any thoughts?

ibc commented 5 years ago

May this commented this._down() affect?

ibc commented 5 years ago

Here a gist that perfectly reproduces the problem:

https://gist.github.com/ibc/e0eb0a0d1f2b2e66f04650c468e65a9a

As you can see, the script never ends:

$ node test.js

sctpSocket created and connecting
closing udpSocket and sctpSocket...
udpSocket.close() called
sctpSocket.end() called
sctpSocket.destroy() failed: Error [ERR_SOCKET_DGRAM_NOT_RUNNING]: Not running
done, this script should exit now, does it?

(no, it does never exit)

ibc commented 5 years ago

Oh, I got the issue! It's in lib/endpoint.js in the Endpoint constructor:

setInterval(() => {
  // TODO change interval when valid_cookie_life changes
  this.cookieSecretKey = crypto.randomBytes(32)
}, this.valid_cookie_life * 5)

This periodic timer is never cleared. By commenting it out, the test above does end.

ibc commented 5 years ago

And PR #12 sent :)

latysheff commented 5 years ago

give me couple of days please)

ibc commented 5 years ago

Sure :)