josephg / ShareJS

Collaborative editing in any app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[mysql] Version 0.6.0: Error: Connection lost: The server closed the connection.

nareshv opened this issue · comments

server running at http://localhost:8000
An error has occurred. Please file a ticket here: https://github.com/josephg/ShareJS/issues
Version 0.6.0: Error: Connection lost: The server closed the connection.
at Protocol.end (~/node-app/ShareJS/node_modules/mysql/lib/protocol/Protocol.js:72:13)
at Socket.onend (stream.js:66:10)
at Socket.EventEmitter.emit (events.js:126:20)
at TCP.onread (net.js:418:51)

Happening with long running server. Found some links which talk about handling this. Am not a coffeescript expert. Appreciated if error handling is supported in the db/mysql.coffee script

mysqljs/mysql@e5b6e1b

or implement pooling support in mysql

https://github.com/felixge/node-mysql/blob/master/Readme.md#pooling-connections

I have this problem as well; it seems you're meant to set a handler on your mysql client that reconnects on an error, as you do in your gist.

You can get around this by creating the mysql client in your own code, setting the error handler on it, and then passing that connection to shareJS instead of letting shareJS create the connection:

awesome_client = mysql.createConnection(...credentials...);

awesome_client.on("error", function (err) {
 ... examine error and reconnect if possible.
})

sharejs.server.attach(app, {
  client: awesome_client,
  ... other awesome options ...
}); 

I'm not sure this is the best solution. The connection times out for a reason, so waking it up just for kicks seems wasteful.

I guess the MySQL db adapter should check that its connected every time it tries to send queries?

I'm new to node and long-running processes, so I'm not sure what the best practice is here.

If the adapter asked for a connection on each request and closed the connection when it was finished, I think it would fix this problem and perhaps support pooling connections.

currently i am using forever to restart once the app is died due to reconnect exception. All other approaches didn't work well for me.