From 0a9dda534c07d30677424fcc80f83d468409e994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nerijus=20Bend=C5=BEi=C5=ABnas?= Date: Sun, 7 Jun 2026 11:09:11 +0300 Subject: [PATCH] Fix data race by reloading satellites on the main thread MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mod_mgr_reload_sats() manipulates GTK widgets but ran on the background TLE update thread, racing the main loop that reads the same state. Schedule the reload on the main loop via an idle callback so all GTK access stays on the main thread. Signed-off-by: Nerijus Bendžiūnas --- src/main.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index f1591774..d01ce654 100644 --- a/src/main.c +++ b/src/main.c @@ -84,6 +84,7 @@ static void gpredict_sig_handler(int sig); static gboolean tle_mon_task(gpointer data); static void tle_mon_stop(void); static gpointer update_tle_thread(gpointer data); +static gboolean reload_sats_idle_cb(gpointer data); static void clean_tle(void); static void clean_trsp(void); @@ -557,10 +558,23 @@ static void tle_mon_stop() /* if TLE update is running wait until it is finished */ while (tle_upd_running) { + /* iterate the main loop so the reload idle callback can run */ + g_main_context_iteration(NULL, FALSE); g_usleep(1000); } } +/* Reload satellites on the main loop after a TLE update. */ +static gboolean reload_sats_idle_cb(gpointer data) +{ + (void)data; + + mod_mgr_reload_sats(); + tle_upd_running = FALSE; + + return G_SOURCE_REMOVE; +} + /* Thread function which invokes TLE update */ static gpointer update_tle_thread(gpointer data) { @@ -568,8 +582,9 @@ static gpointer update_tle_thread(gpointer data) tle_upd_running = TRUE; tle_update_from_network(TRUE, NULL, NULL, NULL); - mod_mgr_reload_sats(); - tle_upd_running = FALSE; + + /* reloading touches GTK, so run it on the main thread, not here */ + gdk_threads_add_idle(reload_sats_idle_cb, NULL); return NULL; }