moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

How to detect and close a dead connection about the server? #637

Open pzx601917159 opened 7 years ago

pzx601917159 commented 7 years ago

Client connect without any packet,and the client internet is unavailable.

mcollina commented 7 years ago

Can you upload an example?

pzx601917159 commented 7 years ago

Sorry,it's just happened in my online server.Running longer, more dead connections(without any packet with tcpdump).I used the setKeepAlive option when authenticate,but it's not work(maybe not emit authenticate).

pzx601917159 commented 7 years ago

Thank you.I solved the problem today.I use my 4g phone telnet to mosca server,and close my 4g network.The problem is happend.The client will not release forever(until close the server).It's may happend in some weak network place。Is it a bug?May i pull request to mosca?Mosca allow a tcp connect without any mqtt packet. So i modify mosca/lib/client.js: 1st init keepalive in client construct: this.keepalive = 5; 2nd add setuptimer int Client.prototype._setup function start: that.setUpTimer(); I use the timer to close the illegal tcp connection(may be dead connection),and it's work.

mcollina commented 7 years ago

That's a similar approach I had in aedes. However, this will likely need another timer, as that one is a keepalive one (with its own logic). Would you like to send a PR?

https://github.com/mcollina/aedes#aedesopts

pzx601917159 commented 7 years ago

My pleasure.