File tree 3 files changed +34
-3
lines changed
packages/socket.io-client
3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ permissions:
14
14
jobs :
15
15
test-browser :
16
16
runs-on : ubuntu-latest
17
- timeout-minutes : 10
17
+ timeout-minutes : 20
18
18
19
19
steps :
20
20
- name : Checkout repository
Original file line number Diff line number Diff line change @@ -531,7 +531,6 @@ export class Manager<
531
531
this . skipReconnect = true ;
532
532
this . _reconnecting = false ;
533
533
this . onclose ( "forced close" ) ;
534
- if ( this . engine ) this . engine . close ( ) ;
535
534
}
536
535
537
536
/**
@@ -544,14 +543,19 @@ export class Manager<
544
543
}
545
544
546
545
/**
547
- * Called upon engine close.
546
+ * Called when:
547
+ *
548
+ * - the low-level engine is closed
549
+ * - the parser encountered a badly formatted packet
550
+ * - all sockets are disconnected
548
551
*
549
552
* @private
550
553
*/
551
554
private onclose ( reason : string , description ?: DisconnectDescription ) : void {
552
555
debug ( "closed due to %s" , reason ) ;
553
556
554
557
this . cleanup ( ) ;
558
+ this . engine ?. close ( ) ;
555
559
this . backoff . reset ( ) ;
556
560
this . _readyState = "closed" ;
557
561
this . emitReserved ( "close" , reason , description ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import hasCORS from "has-cors";
4
4
import { install } from "@sinonjs/fake-timers" ;
5
5
import textBlobBuilder from "text-blob-builder" ;
6
6
import { BASE_URL , wrap } from "./support/util" ;
7
+ import { nextTick } from "engine.io-client" ;
7
8
8
9
describe ( "connection" , ( ) => {
9
10
it ( "should connect to localhost" , ( ) => {
@@ -896,4 +897,30 @@ describe("connection", () => {
896
897
} ) ;
897
898
} ) ;
898
899
} ) ;
900
+
901
+ it ( "should close the engine upon decoding exception" , ( ) => {
902
+ return wrap ( ( done ) => {
903
+ const manager = new Manager ( BASE_URL , {
904
+ autoConnect : true ,
905
+ reconnectionDelay : 50 ,
906
+ } ) ;
907
+
908
+ let engine = manager . engine ;
909
+
910
+ manager . on ( "open" , ( ) => {
911
+ nextTick ( ( ) => {
912
+ // @ts -expect-error emit() is private
913
+ manager . engine . emit ( "data" , "bad" ) ;
914
+ } ) ;
915
+ } ) ;
916
+
917
+ manager . on ( "reconnect" , ( ) => {
918
+ expect ( manager . engine === engine ) . to . be ( false ) ;
919
+ expect ( engine . readyState ) . to . eql ( "closed" ) ;
920
+
921
+ manager . _close ( ) ;
922
+ done ( ) ;
923
+ } ) ;
924
+ } ) ;
925
+ } ) ;
899
926
} ) ;
You can’t perform that action at this time.
0 commit comments