Closed jmholzinger closed 7 years ago
I think you should try to attach a debugger and see what's happening, and where the error is firing.
I do not think is a good idea to handle this error. Given the amount of messages Mosca can receive, if the connection to Mongo fail is safer to fail early and restart. Long-term, handling those types of error conditions leads to memory leaks, file descriptor leaks and a lot of other very bad things.
While I agree with your concerns I'm inclined to disagree that the error should not be handled, mongodb connections are supposed to be fault tolerant, this is why they offer an autoReconnect option.
I will attempt to further debug this issue when I get a chance and report my findings here.
Feel free to send a PR if you discover if we are missing something here.
I wasn't able to pinpoint the problem area, but I was able to determine that the way mosca works won't suit my needs, when the connection does recover the broker attempts to bind to the port again causing another crash. Fortunately I was able to switch to aedes and this problem is no longer occurring. At this point I don't think a PR is necessary, the library just doesn't seem to support my use-case.
I've been experiencing an "unrecoverable" error which seems to come from mosca's mongodb backend/persistence layer. If the mongodb server connection is ended abruptly, sometimes a "write after end" error is thrown causing the process to crash due to an unhandledException, even though error listeners are registered on the server.
My goal is to recover in the event the mongodb server goes down momentarily, so I would like to handle this error, but it is never passed up to an error handler I have control over, even if I pass the db connection to mosca. I'm avoiding handling this error at the process level at all costs.
Here's the stack trace I get when the process crashes:
And the activity in the mongodb logs just before the process crashes:
I'm personally using mongoose to open and manage the database connection like so:
But the error is reproducible when creating the connection using the native driver:
As well as the built in mosca functionality:
I've opened this issue with "mongodb-core" to see if they had any feedback, but I'm not convinced the problem is coming from their end, you can find that issue here: https://github.com/christkv/mongodb-core/issues/179
Any feedback related to this issue would be appreciated. Thanks.