Skip to content

Commit

Permalink
route connection time errors from handshke command to a connection. f…
Browse files Browse the repository at this point in the history
…ixes sidorares#96
  • Loading branch information
sidorares committed Apr 29, 2014
1 parent 3d688dd commit 06ec0ec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Backlog:
- custom typeCast handlers in generated parser #39

HEAD

0.12.0 - 29/04/2014

- route connection time errors from handshke command to
connection #96

- support for nestTables and rowsAsArray options in query()
and execute() #95, #94

- bugfix: date as parameter in prepared statement,
day of week was used incorrectly
instead of day of month #89 ab28dfca839728dfe40d941091902185d7c19b57
Expand Down
5 changes: 4 additions & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ function Connection(opts)
connection.emit('error', err);

});
var handshakeCommand;
if (!this.config.isServer) {
this.addCommand(new Commands.ClientHandshake(this.config.clientFlags));
handshakeCommand = new Commands.ClientHandshake(this.config.clientFlags);
handshakeCommand.on('error', function(e) { connection.emit('error', e); });
this.addCommand(handshakeCommand);
}
}
util.inherits(Connection, EventEmitter);
Expand Down
24 changes: 24 additions & 0 deletions test/integration/connection/test-handshake-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var common = require('../../common');
var assert = require('assert');

var conns = [];

function spawn() {
var c = common.createConnection();
c.ping(spawn);
conns.push(c);

c.on('error', function(err) {
conns.forEach(function(c) { if (c) c.end(); })
});
}

spawn();

process.on('uncaughtException', function(e) {
assert(false, 'should not have uncaught exceptions');
});

process.on('exit', function() {
assert(conns.length > 0);
});

0 comments on commit 06ec0ec

Please sign in to comment.