File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 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){
525525 if ( err ) {
526526 return self . error ( err . data || err . message ) ;
527527 }
528- emit . apply ( self , event ) ;
528+ if ( self . connected ) {
529+ emit . apply ( self , event ) ;
530+ } else {
531+ debug ( "ignore packet received after disconnection" ) ;
532+ }
529533 } ) ;
530534 }
531535 this . run ( event , dispatchSocket ) ;
Original file line number Diff line number Diff line change @@ -1838,6 +1838,33 @@ describe('socket.io', function(){
18381838 } ) ;
18391839 } ) ;
18401840
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+
18411868 it ( 'should always trigger the callback (if provided) when joining a room' , function ( done ) {
18421869 var srv = http ( ) ;
18431870 var sio = io ( srv ) ;
You can’t perform that action at this time.
0 commit comments