Skip to content

Commit 6826e9a

Browse files
authored
fix: unregister "unhandled" event when socket is closed (#224)
This addresses the Memory Leak warning mentioned in #223
1 parent a110e81 commit 6826e9a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/routes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ const setupRoutes = function setupRoutes() {
100100

101101
// #138. handle emitted events that don't have a listener registered, and forward the message
102102
// onto the client via the socket
103-
this.on('unhandled', ({ eventName, data }) => send(prep({ action: eventName, data })));
103+
const unhandled = ({ eventName, data }) => send(prep({ action: eventName, data }));
104+
this.on('unhandled', unhandled);
105+
socket.on('close', () => {
106+
this.off('unhandled', unhandled);
107+
});
104108

105109
send(prep({ action: 'connected' }));
106110
}

0 commit comments

Comments
 (0)