Skip to content

Commit 4403da3

Browse files
committed
fixup! Fix suppression of fatal protocol server errors
1 parent 74f37f3 commit 4403da3

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/Connection.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function Connection(options) {
1515

1616
this.config = options.config;
1717

18+
this._buffer = [];
1819
this._socket = options.socket;
1920
this._protocol = new Protocol({config: this.config, connection: this});
2021
this._connectCalled = false;
@@ -81,8 +82,16 @@ Connection.prototype.connect = function connect(options, callback) {
8182
}
8283

8384
var connection = this;
84-
this._protocol.on('data', function(data) {
85-
connection._socket.write(data);
85+
var onWrite = function onWrite() {
86+
if (connection._buffer.shift() && connection._buffer.length > 0) {
87+
connection._socket.write(connection._buffer[0], onWrite);
88+
}
89+
};
90+
91+
this._protocol.on('data', function (data) {
92+
if (connection._buffer.push(data) === 1) {
93+
connection._socket.write(data, onWrite);
94+
}
8695
});
8796
this._socket.on('data', wrapToDomain(connection, function (data) {
8897
connection._protocol.write(data);
@@ -415,11 +424,7 @@ Connection.prototype._handleConnectTimeout = function() {
415424
};
416425

417426
Connection.prototype._handleNetworkError = function(err) {
418-
if (err.code === 'EPIPE' && err.syscall === 'write') {
419-
setTimeout(this._protocol.handleNetworkError.bind(this._protocol, err), 10);
420-
} else {
421-
this._protocol.handleNetworkError(err);
422-
}
427+
this._protocol.handleNetworkError(err);
423428
};
424429

425430
Connection.prototype._handleProtocolError = function(err) {

0 commit comments

Comments
 (0)