From dc7d3fa77a521040634d68969015bc5cb7ed557f Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 22 Mar 2024 10:22:04 +0000 Subject: [PATCH] Bugfix: stale HTTP connections may get missed in `cleanInactive` method (#2741) This PR fixes the `cleanInactive` method. By code inspection if a stale connection is deleted from the list then the loop index is increment, skipping over the next item. --- Sming/Components/Network/src/Network/HttpClient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sming/Components/Network/src/Network/HttpClient.cpp b/Sming/Components/Network/src/Network/HttpClient.cpp index 0d54aeff5f..7c97be2d6e 100644 --- a/Sming/Components/Network/src/Network/HttpClient.cpp +++ b/Sming/Components/Network/src/Network/HttpClient.cpp @@ -68,13 +68,16 @@ void HttpClient::cleanInactive() { debug_d("Total connections: %d", httpConnectionPool.count()); - for(size_t i = 0; i < httpConnectionPool.count(); i++) { + size_t i = 0; + while(i < httpConnectionPool.count()) { auto connection = httpConnectionPool.valueAt(i); if(connection->getConnectionState() > eTCS_Connecting && !connection->isActive()) { debug_d("Removing stale connection: State: %d, Active: %d, Finished: %d", connection->getConnectionState(), connection->isActive(), connection->isFinished()); httpConnectionPool.removeAt(i); + } else { + ++i; } } }