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 @@ -525,7 +525,11 @@ Socket.prototype.dispatch = function(event){
525
525
if ( err ) {
526
526
return self . error ( err . data || err . message ) ;
527
527
}
528
- emit . apply ( self , event ) ;
528
+ if ( self . connected ) {
529
+ emit . apply ( self , event ) ;
530
+ } else {
531
+ debug ( "ignore packet received after disconnection" ) ;
532
+ }
529
533
} ) ;
530
534
}
531
535
this . run ( event , dispatchSocket ) ;
Original file line number Diff line number Diff line change @@ -1838,6 +1838,33 @@ describe('socket.io', function(){
1838
1838
} ) ;
1839
1839
} ) ;
1840
1840
1841
+ it ( "should ignore a packet received after disconnection" , ( done ) => {
1842
+ const srv = http ( ) ;
1843
+ const sio = io ( srv ) ;
1844
+
1845
+ srv . listen ( ( ) => {
1846
+ const clientSocket = client ( srv ) ;
1847
+
1848
+ const success = ( ) => {
1849
+ clientSocket . close ( ) ;
1850
+ sio . close ( ) ;
1851
+ done ( ) ;
1852
+ } ;
1853
+
1854
+ sio . on ( "connection" , ( socket ) => {
1855
+ socket . on ( "test" , ( ) => {
1856
+ done ( new Error ( "should not happen" ) ) ;
1857
+ } ) ;
1858
+ socket . on ( "disconnect" , success ) ;
1859
+ } ) ;
1860
+
1861
+ clientSocket . on ( "connect" , ( ) => {
1862
+ clientSocket . emit ( "test" , Buffer . alloc ( 10 ) ) ;
1863
+ clientSocket . disconnect ( ) ;
1864
+ } ) ;
1865
+ } ) ;
1866
+ } ) ;
1867
+
1841
1868
it ( 'should always trigger the callback (if provided) when joining a room' , function ( done ) {
1842
1869
var srv = http ( ) ;
1843
1870
var sio = io ( srv ) ;
You can’t perform that action at this time.
0 commit comments