From b79b6b6ef57fcd19fabd94f83fd9a0a1b8c7c590 Mon Sep 17 00:00:00 2001 From: Dmytro Lipunov Date: Wed, 22 Jul 2026 09:45:45 +0200 Subject: [PATCH] Drop idle persistent agent sockets after fatal failures --- src/searchdha.cpp | 19 ++++++++++++++++++- src/searchdha.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/searchdha.cpp b/src/searchdha.cpp index c511d5cd0c..65c5562c98 100644 --- a/src/searchdha.cpp +++ b/src/searchdha.cpp @@ -237,6 +237,22 @@ void PersistentConnectionsPool_c::ReturnConnection ( int iSocket ) m_dSockets[Step ( &m_iWit )] = iSocket; } +void PersistentConnectionsPool_c::CloseIdleConnections () +{ + ScopedMutex_t tGuard ( m_dDataLock ); + + int iRead = m_iRit; + for ( int i = 0; i=0 ) + { + sphSockClose ( iSock ); + iSock = -1; + } + } +} + // close all the sockets in the pool. void PersistentConnectionsPool_c::Shutdown () { @@ -1662,6 +1678,8 @@ bool AgentConn_t::Fatal ( AgentStats_e eStat, const char * sMessage, ... ) va_end ( ap ); sphLogDebugv ( "%d FATAL: %s", m_iStoreTag, m_sFailure.cstr () ); // want to log failure at extended log mode wo recompile of daemon State ( Agent_e::RETRY ); + if ( IsPersistent () ) + m_tDesc.m_pDash->m_pPersPool->CloseIdleConnections (); Finish ( true ); agent_stats_inc ( *this, eStat ); return false; @@ -3894,4 +3912,3 @@ bool sphNBSockEof ( int iSock ) return true; return false; } - diff --git a/src/searchdha.h b/src/searchdha.h index 032ff0459f..0655fde789 100644 --- a/src/searchdha.h +++ b/src/searchdha.h @@ -132,6 +132,7 @@ class PersistentConnectionsPool_c void ReInit ( int iPoolSize ) REQUIRES ( !m_dDataLock ); int RentConnection () REQUIRES ( !m_dDataLock ); void ReturnConnection ( int iSocket ) REQUIRES ( !m_dDataLock ); + void CloseIdleConnections () REQUIRES ( !m_dDataLock ); void Shutdown () REQUIRES ( !m_dDataLock ); };