File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
packages/socket.io-client Expand file tree Collapse file tree 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" , ( ) => {
@@ -894,4 +895,30 @@ describe("connection", () => {
894
895
} ) ;
895
896
} ) ;
896
897
} ) ;
898
+
899
+ it ( "should close the engine upon decoding exception" , ( ) => {
900
+ return wrap ( ( done ) => {
901
+ const manager = new Manager ( BASE_URL , {
902
+ autoConnect : true ,
903
+ reconnectionDelay : 50 ,
904
+ } ) ;
905
+
906
+ let engine = manager . engine ;
907
+
908
+ manager . on ( "open" , ( ) => {
909
+ nextTick ( ( ) => {
910
+ // @ts -expect-error emit() is private
911
+ manager . engine . emit ( "data" , "bad" ) ;
912
+ } ) ;
913
+ } ) ;
914
+
915
+ manager . on ( "reconnect" , ( ) => {
916
+ expect ( manager . engine === engine ) . to . be ( false ) ;
917
+ expect ( engine . readyState ) . to . eql ( "closed" ) ;
918
+
919
+ manager . _close ( ) ;
920
+ done ( ) ;
921
+ } ) ;
922
+ } ) ;
923
+ } ) ;
897
924
} ) ;
You can’t perform that action at this time.
0 commit comments