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 @@ -537,7 +537,11 @@ export class Socket extends EventEmitter {
537537 if ( err ) {
538538 return this . _onerror ( err ) ;
539539 }
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+ }
541545 } ) ;
542546 } ) ;
543547 }
Original file line number Diff line number Diff line change @@ -1787,6 +1787,33 @@ describe("socket.io", () => {
17871787 } ) ;
17881788 } ) ;
17891789
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+
17901817 describe ( "onAny" , ( ) => {
17911818 it ( "should call listener" , ( done ) => {
17921819 const srv = createServer ( ) ;
You can’t perform that action at this time.
0 commit comments