fix order of operations

This commit is contained in:
zefie
2025-06-22 15:41:29 -04:00
parent 051ea84f81
commit 4f289ea161

View File

@@ -91,7 +91,7 @@ class WTVIRC {
this.awaylen = this.irc_config.away_len || 200; this.awaylen = this.irc_config.away_len || 200;
this.enable_tls = this.irc_config.enable_ssl || false; this.enable_tls = this.irc_config.enable_ssl || false;
this.maxtargets = this.irc_config.max_targets || 4; this.maxtargets = this.irc_config.max_targets || 4;
this.socket_timeout = 60000; // Default socket timeout to 120 seconds this.socket_timeout = 90000; // Default socket timeout to 120 seconds
this.server_hello = this.irc_config.server_hello || `zefIRCd v${this.version} IRC server powered by minisrv`; this.server_hello = this.irc_config.server_hello || `zefIRCd v${this.version} IRC server powered by minisrv`;
this.enable_eval = this.debug || false; // Enable eval in debug mode only this.enable_eval = this.debug || false; // Enable eval in debug mode only
this.serverId = this.irc_config.server_id || '00A'; // Default server ID, can be overridden in config this.serverId = this.irc_config.server_id || '00A'; // Default server ID, can be overridden in config
@@ -302,20 +302,21 @@ class WTVIRC {
return; return;
} }
const now = Date.now(); const now = Date.now();
if ((now - socket.lastseen) > this.socket_timeout) { // 60 seconds if ((now - socket.lastseen) > this.socket_timeout + 10000) {
// Over 10 seconds has passed since we sent our PING, assume lost
this.debugLog('warn', `Socket ${socket.remoteAddress} has been idle for too long, terminating session`);
if (socket.nickname) {
this.broadcastUser(socket.nickname, `:${socket.nickname}!${socket.username}@${socket.host} QUIT :Ping timeout (${Math.floor((now - socket.lastseen) / 1000)} seconds)\r\n`, socket);
}
this.terminateSession(socket, true);
return;
} else if ((now - socket.lastseen) > this.socket_timeout) {
// Client has been idle for too long, send PING
this.safeWriteToSocket(socket, `PING :${this.servername}\r\n`); this.safeWriteToSocket(socket, `PING :${this.servername}\r\n`);
this.debugLog('info', `Sent PING to ${socket.remoteAddress} due to inactivity`); this.debugLog('info', `Sent PING to ${socket.remoteAddress} due to inactivity`);
return; return;
} }
if ((now - socket.lastseen) > this.socket_timeout * 2) { // If the socket has been idle for too long }, 5000); // check every 5 seconds
this.debugLog('warn', `Socket ${socket.remoteAddress} has been idle for too long, terminating session`);
if (socket.nickname) {
this.broadcastUser(socket.nickname, `:${socket.nickname}!${socket.username}@${socket.host} QUIT :Ping timeout (${Math.floor((now - socket.lastseen) / 1000)} seconds)\r\n`);
}
this.terminateSession(socket, true);
return;
}
}, 10000); // check every 10 seconds
this.clients.push(socket); this.clients.push(socket);
this.clientpeak = Math.max(this.clientpeak, this.clients.length); this.clientpeak = Math.max(this.clientpeak, this.clients.length);