@@ -156,9 +156,6 @@ Protocol.prototype._enqueue = function(sequence) {
156156 sequence . _timer . active ( ) ;
157157 self . _emitPacket ( packet ) ;
158158 } )
159- . on ( 'end' , function ( ) {
160- self . _dequeue ( sequence ) ;
161- } )
162159 . on ( 'timeout' , function ( ) {
163160 var err = new Error ( sequence . constructor . name + ' inactivity timeout' ) ;
164161
@@ -185,8 +182,20 @@ Protocol.prototype._enqueue = function(sequence) {
185182 sequence . _tlsUpgradeCompleteHandler ( ) ;
186183 } ) ;
187184 } ) ;
185+
186+ sequence . on ( 'end' , function ( ) {
187+ self . _handshaked = true ;
188+
189+ if ( ! self . _fatalError ) {
190+ self . emit ( 'handshake' , self . _handshakeInitializationPacket ) ;
191+ }
192+ } ) ;
188193 }
189194
195+ sequence . on ( 'end' , function ( ) {
196+ self . _dequeue ( sequence ) ;
197+ } ) ;
198+
190199 if ( this . _queue . length === 1 ) {
191200 this . _parser . resetPacketNumber ( ) ;
192201 this . _startSequence ( sequence ) ;
@@ -311,12 +320,7 @@ Protocol.prototype._determinePacket = function(sequence) {
311320 }
312321
313322 switch ( firstByte ) {
314- case 0x00 :
315- if ( ! this . _handshaked ) {
316- this . _handshaked = true ;
317- this . emit ( 'handshake' , this . _handshakeInitializationPacket ) ;
318- }
319- return Packets . OkPacket ;
323+ case 0x00 : return Packets . OkPacket ;
320324 case 0xfe : return Packets . EofPacket ;
321325 case 0xff : return Packets . ErrorPacket ;
322326 }
0 commit comments