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:
1414jobs :
1515 test-browser :
1616 runs-on : ubuntu-latest
17- timeout-minutes : 10
17+ timeout-minutes : 20
1818
1919 steps :
2020 - name : Checkout repository
Original file line number Diff line number Diff line change @@ -531,7 +531,6 @@ export class Manager<
531531 this . skipReconnect = true ;
532532 this . _reconnecting = false ;
533533 this . onclose ( "forced close" ) ;
534- if ( this . engine ) this . engine . close ( ) ;
535534 }
536535
537536 /**
@@ -544,14 +543,19 @@ export class Manager<
544543 }
545544
546545 /**
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
548551 *
549552 * @private
550553 */
551554 private onclose ( reason : string , description ?: DisconnectDescription ) : void {
552555 debug ( "closed due to %s" , reason ) ;
553556
554557 this . cleanup ( ) ;
558+ this . engine ?. close ( ) ;
555559 this . backoff . reset ( ) ;
556560 this . _readyState = "closed" ;
557561 this . emitReserved ( "close" , reason , description ) ;
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import hasCORS from "has-cors";
44import { install } from "@sinonjs/fake-timers" ;
55import textBlobBuilder from "text-blob-builder" ;
66import { BASE_URL , wrap } from "./support/util" ;
7+ import { nextTick } from "engine.io-client" ;
78
89describe ( "connection" , ( ) => {
910 it ( "should connect to localhost" , ( ) => {
@@ -896,4 +897,30 @@ describe("connection", () => {
896897 } ) ;
897898 } ) ;
898899 } ) ;
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+ } ) ;
899926} ) ;
You can’t perform that action at this time.
0 commit comments