Skip to content

Commit 564f1ac

Browse files
committed
* handle end and begin on same channel in same frame
* ensure protocol errors are passed in disconnect context
1 parent cb7d2e4 commit 564f1ac

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/connection.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ Connection.prototype.output = function () {
464464
}
465465
}
466466
} catch (e) {
467+
this.saved_error = e;
467468
if (e.name === 'ProtocolError') {
468469
console.error('[' + this.options.id + '] error on write: ' + e + ' ' + this._get_peer_details() + ' ' + e.name);
469470
this.dispatch('protocol_error', e) || console.error('[' + this.options.id + '] error on write: ' + e + ' ' + this._get_peer_details());
@@ -511,6 +512,7 @@ Connection.prototype.input = function (buff) {
511512
this.heartbeat_out = setTimeout(this._write_frame.bind(this), this.remote.open.idle_time_out / 2);
512513
}
513514
} catch (e) {
515+
this.saved_error = e;
514516
if (e.name === 'ProtocolError') {
515517
this.dispatch('protocol_error', e) ||
516518
console.error('[' + this.options.id + '] error on read: ' + e + ' ' + this._get_peer_details() + ' (buffer:' + buffer_to_hex(buffer) + ')');
@@ -535,7 +537,9 @@ Connection.prototype.on_error = function (e) {
535537
};
536538

537539
Connection.prototype.eof = function (e) {
538-
this._disconnected(e);
540+
var error = e || this.saved_error;
541+
this.saved_error = undefined;
542+
this._disconnected(error);
539543
};
540544

541545
Connection.prototype._disconnected = function (error) {
@@ -734,8 +738,12 @@ Connection.prototype._context = function (c) {
734738
};
735739

736740
Connection.prototype.remove_session = function (session) {
737-
delete this.remote_channel_map[session.remote.channel];
738-
delete this.local_channel_map[session.local.channel];
741+
if (this.remote_channel_map[session.remote.channel] === session) {
742+
delete this.remote_channel_map[session.remote.channel];
743+
}
744+
if (this.local_channel_map[session.local.channel] === session) {
745+
delete this.local_channel_map[session.local.channel];
746+
}
739747
};
740748

741749
Connection.prototype.remove_all_sessions = function () {

0 commit comments

Comments
 (0)