8000 Make sure to catch all stream errors on connect · mysqljs/mysql@22adb45 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22adb45

Browse files
committed
Make sure to catch all stream errors on connect
It seems like some stream errors may occur sync, so one has to attach an error listener to the stream before executing `connect`. I'm not sure if this is how things should behave, will clarify with Ryan.
1 parent 99cad60 commit 22adb45

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/mysql/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Client.prototype.connect = function(cb) {
4848
var connection = self._connection = new Stream(),
4949
parser = self._parser = new Parser();
5050

51-
connection.connect(self.port, self.host);
5251
connection
5352
.on('error', function(err) {
5453
if (err.errno & (netBinding.ECONNREFUSED | netBinding.ENOTFOUND)) {
@@ -77,6 +76,7 @@ Client.prototype.connect = function(cb) {
7776
self.connected = false;
7877
self._prequeue(connect);
7978
});
79+
connection.connect(self.port, self.host);
8080

8181
parser
8282
.on('packet', function(packet) {

test/simple/test-client.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ test(function connect() {
7474
gently.expect(StreamStub, 'new', function() {
7575
CONNECTION = this;
7676

77-
gently.expect(CONNECTION, 'connect', function(port, host) {
78-
assert.equal(port, client.port);
79-
assert.equal(host, client.host);
80-
});
81-
8277
var events = ['error', 'data', 'end'];
8378
gently.expect(CONNECTION, 'on', events.length, function(event, fn) {
8479
assert.equal(event, events.shift());
8580
onConnection[event] = fn;
8681
return this;
8782
});
83+
84+
gently.expect(CONNECTION, 'connect', function(port, host) {
85+
assert.equal(port, client.port);
86+
assert.equal(host, client.host);
87+
});
8888
});
8989

9090
gently.expect(ParserStub, 'new', function() {

0 commit comments

Comments
 (0)
0