Fixes: Socket not cleanly closed after ECONNRESET

Nodejs 0.10.20 throw an "ECONNRESET" error when the socket is reset. After this exception, the socket wasn't cleanly closed, causing a weird behavior.

Pull request based on the solution given in bug report #1343

Some related issues: #1281 #1367