Add reconnection delay to prevent high CPU usage when server is unavailable. (#7736)

When the websocket server is unavailable the connection tries to reconnect too fast causing a high CPU usage. Adding a check for the connection status and sleeping when it is not yet connected after a re-connect attempt prevents the high CPU usage.

Fixed the method signature in create_filter_chain_for to exactly match that of the parent to avoid potential PHP warnings or errors.
This commit is contained in:
frytimo
2026-02-06 10:24:33 -04:00
committed by GitHub
parent 03ff47dc59
commit bfcdef308d
2 changed files with 7 additions and 2 deletions

View File

@@ -178,9 +178,9 @@ class active_conferences_service extends base_websocket_system_service implement
*
* @param subscriber $subscriber
*
* @return filter
* @return filter|null
*/
public static function create_filter_chain_for(subscriber $subscriber): filter {
public static function create_filter_chain_for(subscriber $subscriber): ?filter {
// Domain filtering for conferences
if ($subscriber->has_permission('conference_active_view')) {
return filter_chain::and_link([

View File

@@ -167,6 +167,11 @@ abstract class base_websocket_system_service extends service implements websocke
if (!$suppress_ws_message) $this->error("Unable to connect to websocket server.");
$suppress_ws_message = true;
}
if (!$this->ws_client->is_connected()) {
// Sleep for a bit before trying to reconnect to prevent flooding the logs with connection errors
sleep(1);
continue;
}
}
if ($this->ws_client !== null && $this->ws_client->is_connected()) {