sidorares/nodejs-mysql-native — Issue #51: Handle socket errors
Author: marcuswestin
Created: 2011-11-17 19:18:31+00:00
State: open

It seems like all socket errors are not being handled.

This example calling code:

mysqlClient.query(params.query)
.on('error', function(err) {
sendError(res, err)
})
.on(....)

ended up with this stack trace:

Error: Socket is not writable
at Socket._writeOut (net.js:391:11)
at Socket.write (net.js:377:17)
at cmd.write (code/node_modules/mysql/lib/mysql-native/command.js:61:19)
at cmd.start (code/node_modules/mysql/lib/mysql-native/commands/query.js:107:12)
at cmd.process_packet (code/node_modules/mysql/lib/mysql-native/command.js:45:58)
at SocketClient.dispatch_packet (code/node_modules/mysql/lib/mysql-native/socketclient.js:105:32)
at SocketClient.add (code/node_modules/mysql/lib/mysql-native/socketclient.js:123:14)
at SocketClient.query (code/node_modules/mysql/lib/mysql-native/socketclient.js:40:21)
at Server. (code/graphs/scripts/run-server.js:31:15)

My best guess is that we should be checking in `command.js`

if (!connection.write) {
listen for connection 'drain' event and then keep writing
}

At least the 'error' event should bubble up all the way to the client API, rather than crashing the process.