@@ -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
537539Connection . 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
541545Connection . prototype . _disconnected = function ( error ) {
@@ -734,8 +738,12 @@ Connection.prototype._context = function (c) {
734738} ;
735739
736740Connection . 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
741749Connection . prototype . remove_all_sessions = function ( ) {
0 commit comments