File tree 2 files changed +32
-1
lines changed
2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -537,7 +537,11 @@ export class Socket extends EventEmitter {
537
537
if ( err ) {
538
538
return this . _onerror ( err ) ;
539
539
}
540
- super . emit . apply ( this , event ) ;
540
+ if ( this . connected ) {
541
+ super . emit . apply ( this , event ) ;
542
+ } else {
543
+ debug ( "ignore packet received after disconnection" ) ;
544
+ }
541
545
} ) ;
542
546
} ) ;
543
547
}
Original file line number Diff line number Diff line change @@ -1787,6 +1787,33 @@ describe("socket.io", () => {
1787
1787
} ) ;
1788
1788
} ) ;
1789
1789
1790
+ it ( "should ignore a packet received after disconnection" , ( done ) => {
1791
+ const srv = createServer ( ) ;
1792
+ const sio = new Server ( srv ) ;
1793
+
1794
+ srv . listen ( ( ) => {
1795
+ const clientSocket = client ( srv ) ;
1796
+
1797
+ const success = ( ) => {
1798
+ clientSocket . close ( ) ;
1799
+ sio . close ( ) ;
1800
+ done ( ) ;
1801
+ } ;
1802
+
1803
+ sio . on ( "connection" , ( socket ) => {
1804
+ socket . on ( "test" , ( ) => {
1805
+ done ( new Error ( "should not happen" ) ) ;
1806
+ } ) ;
1807
+ socket . on ( "disconnect" , success ) ;
1808
+ } ) ;
1809
+
1810
+ clientSocket . on ( "connect" , ( ) => {
1811
+ clientSocket . emit ( "test" , Buffer . alloc ( 10 ) ) ;
1812
+ clientSocket . disconnect ( ) ;
1813
+ } ) ;
1814
+ } ) ;
1815
+ } ) ;
1816
+
1790
1817
describe ( "onAny" , ( ) => {
1791
1818
it ( "should call listener" , ( done ) => {
1792
1819
const srv = createServer ( ) ;
You can’t perform that action at this time.
0 commit comments