From 95022ca95b1d2792bae447d90694dcc0d67b9de2 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Thu, 16 Oct 2025 01:35:10 -0300 Subject: lower monotonic uptime resolution from MILLISECONDS to SECONDS The monotonic uptime was used exclusively with caches and having a resolution of SECONDS allows it to be stored as an int without risk of wrapping (~68 years). Using MILLISECONDS meant that it would wrap after ~25 days which is totally possible and EXPECTED. Just as an example, the small test server I ran for about 1 month had ZERO downtime on the QueryManager except for when I manually restarted it. It was probably very close to wrapping when I took it down. --- src/connections.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/connections.cc') diff --git a/src/connections.cc b/src/connections.cc index 0760514..b851954 100644 --- a/src/connections.cc +++ b/src/connections.cc @@ -141,7 +141,7 @@ TConnection *AssignConnection(int Socket, uint32 Addr, uint16 Port){ Connection = &g_Connections[ConnectionIndex]; Connection->State = CONNECTION_READING; Connection->Socket = Socket; - Connection->LastActive = GetMonotonicUptimeMS(); + Connection->LastActive = GetMonotonicUptime(); snprintf(Connection->RemoteAddress, sizeof(Connection->RemoteAddress), "%d.%d.%d.%d:%d", @@ -215,7 +215,7 @@ void CheckConnectionInput(TConnection *Connection, int Events){ if(Connection->RWPosition >= ReadSize){ if(Connection->RWSize != 0){ Connection->State = CONNECTION_REQUEST; - Connection->LastActive = GetMonotonicUptimeMS(); + Connection->LastActive = GetMonotonicUptime(); Connection->Query->Request = TReadBuffer(Buffer, Connection->RWSize); break; }else if(Connection->RWPosition == 2){ @@ -510,8 +510,12 @@ void CheckConnection(TConnection *Connection, int Events){ CloseConnection(Connection); } + // NOTE(fusion): Idle connection could linger for more than expected because + // the polling thread now blocks on `poll`. It shouldn't be a problem tho, as + // it could only happen on periods of absolutely NO traffic, so there is ZERO + // load on the query manager outside of used memory (which is already limited). if(g_Config.MaxConnectionIdleTime > 0){ - int IdleTime = (GetMonotonicUptimeMS() - Connection->LastActive); + int IdleTime = (GetMonotonicUptime() - Connection->LastActive); if(IdleTime >= g_Config.MaxConnectionIdleTime){ LOG_WARN("Dropping connection %s due to inactivity", Connection->RemoteAddress); -- cgit v1.2.3