diff options
| author | Victor Kareh <[email protected]> | 2026-06-01 08:52:41 -0400 |
|---|---|---|
| committer | Luke from DC <[email protected]> | 2026-07-21 05:45:28 +0000 |
| commit | 57a9178e766cd02176dc1c2d70cc48f963ee9fff (patch) | |
| tree | 3ab069747720e5e5a1248a3c2a0649c8a250809d | |
| parent | 8ff528c7942e6b1323aec401e06ba490625d98c9 (diff) | |
| download | mate-session-manager-master.tar.bz2 mate-session-manager-master.tar.xz | |
When a non-client app with AutoRestart enabled exits immediately after
starting, the restart logic would loop without delay, causing high CPU
usage. This adds a 60-second rate limit to gsm_app_restart. If an app
respawns twice within this window, the second restart is rejected.
The code is adapted from:
- https://gitlab.gnome.org/GNOME/gnome-session/-/commit/4df48234
- https://gitlab.gnome.org/GNOME/gnome-session/-/commit/b9aa675e
Fixes #336
| -rw-r--r-- | mate-session/gsm-app.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mate-session/gsm-app.c b/mate-session/gsm-app.c index 0260b21..c37480e 100644 --- a/mate-session/gsm-app.c +++ b/mate-session/gsm-app.c @@ -30,11 +30,15 @@ #include "gsm-app.h" #include "org.gnome.SessionManager.App.h" +/* If a component crashes twice within a minute, we count that as a fatal error */ +#define _GSM_APP_RESPAWN_RATELIMIT_SECONDS 60 + typedef struct { char *id; char *app_id; int phase; char *startup_id; + gint64 last_restart_time; GDBusConnection *connection; GsmExportedApp *skeleton; } GsmAppPrivate; @@ -522,9 +526,24 @@ gsm_app_restart (GsmApp *app, GError **error) { GsmAppPrivate *priv; + gint64 current_time; priv = gsm_app_get_instance_private (app); + current_time = g_get_real_time (); + + if (priv->last_restart_time > 0 + && (current_time - priv->last_restart_time) < _GSM_APP_RESPAWN_RATELIMIT_SECONDS * G_USEC_PER_SEC) { + g_warning ("App '%s' respawning too quickly", priv->app_id ? priv->app_id : priv->id); + g_set_error (error, + GSM_APP_ERROR, + GSM_APP_ERROR_GENERAL, + "Component '%s' crashing too quickly", + priv->app_id ? priv->app_id : priv->id); + return FALSE; + } + priv->last_restart_time = current_time; + g_debug ("Re-starting app: %s", priv->id); return GSM_APP_GET_CLASS (app)->impl_restart (app, error); |
