Merge pull request #2682 from fosrl/dev

Fix offline issue
This commit is contained in:
Owen Schwartz
2026-03-20 15:31:38 -07:00
committed by GitHub
2 changed files with 12 additions and 27 deletions

View File

@@ -38,7 +38,7 @@ export const startRemoteExitNodeOfflineChecker = (): void => {
); );
// Find clients that haven't pinged in the last 2 minutes and mark them as offline // Find clients that haven't pinged in the last 2 minutes and mark them as offline
const newlyOfflineNodes = await db const offlineNodes = await db
.update(exitNodes) .update(exitNodes)
.set({ online: false }) .set({ online: false })
.where( .where(
@@ -53,32 +53,15 @@ export const startRemoteExitNodeOfflineChecker = (): void => {
) )
.returning(); .returning();
// Update the sites to offline if they have not pinged either if (offlineNodes.length > 0) {
const exitNodeIds = newlyOfflineNodes.map( logger.info(
(node) => node.exitNodeId `checkRemoteExitNodeOffline: Marked ${offlineNodes.length} remoteExitNode client(s) offline due to inactivity`
); );
const sitesOnNode = await db for (const offlineClient of offlineNodes) {
.select() logger.debug(
.from(sites) `checkRemoteExitNodeOffline: Client ${offlineClient.exitNodeId} marked offline (lastPing: ${offlineClient.lastPing})`
.where(
and(
eq(sites.online, true),
inArray(sites.exitNodeId, exitNodeIds)
)
); );
// loop through the sites and process their lastBandwidthUpdate as an iso string and if its more than 1 minute old then mark the site offline
for (const site of sitesOnNode) {
if (!site.lastBandwidthUpdate) {
continue;
}
const lastBandwidthUpdate = new Date(site.lastBandwidthUpdate);
if (Date.now() - lastBandwidthUpdate.getTime() > 60 * 1000) {
await db
.update(sites)
.set({ online: false })
.where(eq(sites.siteId, site.siteId));
} }
} }
} catch (error) { } catch (error) {

View File

@@ -6,7 +6,9 @@ import logger from "@server/logger";
/** /**
* Handles disconnecting messages from sites to show disconnected in the ui * Handles disconnecting messages from sites to show disconnected in the ui
*/ */
export const handleNewtDisconnectingMessage: MessageHandler = async (context) => { export const handleNewtDisconnectingMessage: MessageHandler = async (
context
) => {
const { message, client: c, sendToClient } = context; const { message, client: c, sendToClient } = context;
const newt = c as Newt; const newt = c as Newt;
@@ -27,7 +29,7 @@ export const handleNewtDisconnectingMessage: MessageHandler = async (context) =>
.set({ .set({
online: false online: false
}) })
.where(eq(sites.siteId, sites.siteId)); .where(eq(sites.siteId, newt.siteId));
} catch (error) { } catch (error) {
logger.error("Error handling disconnecting message", { error }); logger.error("Error handling disconnecting message", { error });
} }