From 3a75dd9bdd12cdc1295021731c0ba5a5fba913c6 Mon Sep 17 00:00:00 2001 From: Ibn-Butt-Toota <283850630+Ibn-Butt-Toota@users.noreply.github.com> Date: Fri, 30 Oct 2026 00:42:56 -0400 Subject: [PATCH] STUN: stop spamming if a keepalive request cant be sent If a keepalive request fails due to a packet not being able to be sent at all (like if someone's only connection went away due to turning on airplane mode or the interface goes down) then STUN's keepalive would send a request, have it fail, then enqueue another request, which would immediately fail, etc., causing a core to get pinned, which also happens to block anything scheduled, including the connection's timeout. The core is pinned until either: 1) the connection is closed by whatever application is running it or 2) the original address returns. --- .../clientlib/steamnetworkingsockets_ice_client.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.cpp b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.cpp index e5a48147..4de8013e 100644 --- a/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.cpp +++ b/src/steamnetworkingsockets/clientlib/steamnetworkingsockets_ice_client.cpp @@ -2339,6 +2339,18 @@ void CSteamNetworkingICESession::STUNRequestCallback_ServerReflexiveKeepAlive( c const int nSTUNServerIdx = std::max( 0, index_of( m_vecSTUNServers, info.m_pRequest->m_remoteAddr ) ); const int nNextSTUNServerIdx = ( nSTUNServerIdx + 1 ) % len( m_vecSTUNServers ); + + // If the request failed because the packet could not be sent at all (airplane mode + // or connection drops for whatever reason), requeuing right away would spam STUN requests: + // each new request fails immediately and queues another request, causing the service thread + // to never sleep. Instead, we can save the server to try next and leave the attempt to the + // regular keepalive timer. + if ( info.m_pRequest->m_usecLastSentTime == 0 ) + { + pIntf->m_addrSTUNServer = m_vecSTUNServers[ nNextSTUNServerIdx ]; + return; + } + pIntf->QueueBindRequest( m_vecSTUNServers[ nNextSTUNServerIdx ], &CSteamNetworkingICESession::STUNRequestCallback_ServerReflexiveKeepAlive, m_nEncoding ); }