Better stability

Our production servers kept going down, I finally found the server: sometimes the connections not closed.

This fix keeps the server stable now.

Also added an error handler for rare cases.