dead socket kicking and connection info pill

This commit is contained in:
legop3
2026-05-28 22:05:18 -04:00
parent 94ef97f5bb
commit a3d709236c
10 changed files with 162 additions and 12 deletions
@@ -28,6 +28,8 @@ const { createRequestFlow } = require('./requestFlow');
const { registerVerificationHooks } = require('./hooks');
const verificationEvents = new EventEmitter();
const IDENTITY_TIMEOUT_MS = 2 * 60 * 1000;
const IDENTITY_SWEEP_INTERVAL_MS = 15 * 1000;
function emitChange(reason, payload = {}) {
verificationEvents.emit('change', { reason, ...payload });
@@ -145,6 +147,27 @@ registerVerificationHooks({
emitChange,
});
setInterval(() => {
const now = Date.now();
io.sockets.sockets.forEach((socket) => {
if (!socket?.id) return;
const role = getRole(socket);
if (role === 'admin' || role === 'lockdown') return;
const connectedAt = Number(socket?.data?.connectedAt || 0);
const lastClientIdentifyAt = Number(socket?.data?.lastClientIdentifyAt || 0);
const referenceTs = lastClientIdentifyAt || connectedAt;
if (!referenceTs) return;
if (now - referenceTs < IDENTITY_TIMEOUT_MS) return;
logger.info('Disconnecting socket due to stale identity heartbeat', {
socketId: socket.id,
role,
ageMs: now - referenceTs,
hadClientIdentify: Boolean(lastClientIdentifyAt),
});
socket.disconnect(true);
});
}, IDENTITY_SWEEP_INTERVAL_MS);
module.exports = {
identifySocket,
getVerificationStatus: verificationFlow.getVerificationStatus,