Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for endless reconnection problem
* do not generate 'close' event on ping failure - rely on socket 'close' event instead * destroy() socket instead end() to make sure 'close' event comes quickly
- Loading branch information
2e662a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not completely correct, as calling
this.conn.disconnect()
sends a MQTT disconnect message, that must be sent in case of normal close (e.g. through end). callingthis.stream.destroy()
will prevent that message to be sent, whilethis.stream.end()
ensure that.You can get around that problem by adding a parameter to cleanup.
.. and please, add tests!
2e662a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I wasn't too sure about using destroy() here.
I think we may even leave
this.stream.end()
as it was, however, we have to keep in mind it may take a long time before the actualclose
event is generated in case of dropped network. During that time, message are being lost because there is no flag set to indicate the connection is disconnecting.2e662a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better fix here 1090fa6
I'd be happy to submit tests, but how do you actually run these tests?
2e662a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the tests are written in mocha. You can run them by issuing
npm test
ormocha
2e662a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be difficult to include it in an automated testsuite because my test requires root access to modify iptables. See mqttjs#180 for code.
Just stopping the server doesn't do it because that will close the socket as well.