disconnect pong() listener when closing connection

This commit is contained in:
Hazelnoot 2025-08-15 23:32:50 -04:00
parent 840f589651
commit 3770f4a86a

View file

@ -270,8 +270,12 @@ export class StreamingApiServerService implements OnApplicationShutdown {
if (user) {
this.usersService.updateLastActiveDate(user);
}
const pong = () => {
this.#connections.set(connection, Date.now());
};
connection.once('close', () => {
connection.off('pong', pong);
ev.removeAllListeners();
stream.dispose();
this.#globalEv.off('message', onRedisMessage);
@ -279,9 +283,7 @@ export class StreamingApiServerService implements OnApplicationShutdown {
if (userUpdateIntervalId) clearInterval(userUpdateIntervalId);
});
connection.on('pong', () => {
this.#connections.set(connection, Date.now());
});
connection.on('pong', pong);
});
// 一定期間通信が無いコネクションは実際には切断されている可能性があるため定期的にterminateする