Skip to content

Handle socket errors #51

@marcuswestin

Description

@marcuswestin

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.<anonymous> (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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions