Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

fix(linux/gui): a window whose service restarted starts the engine again; test it with a service restart under an open window

anof-cyber9ac074eed365
diff --git a/Linux/gui/main.c b/Linux/gui/main.c
index bddb701..e53d503 100644
--- a/Linux/gui/main.c
+++ b/Linux/gui/main.c
@@ -597,6 +597,7 @@ static GtkWidget *add_flows_tab(GtkWidget *notebook) {
// The service went away (restarted, updated, stopped). Try again every two seconds and send the window's configuration once it is back.
static guint reconnect_source;
+static bool resume_engine; // the engine was running when the connection broke: start it again afterwards
static gboolean reconnect_tick(gpointer data) {
if (!pbc_reconnect()) return G_SOURCE_CONTINUE;
@@ -609,6 +610,8 @@ static gboolean reconnect_tick(gpointer data) {
gui_sync_switches();
ProxyBridge_SetEnabled(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(enable_item)));
set_engine_state(pbc_service_engine_running() ? ENGINE_RUNNING : ENGINE_STOPPED);
+ if (resume_engine) engine_request(true); // a restarted service that is not set to start at boot waits for us
+ resume_engine = false;
gtk_statusbar_push(GTK_STATUSBAR(status_bar), status_context_id, "Connected to the ProxyBridge service again.");
gui_log("connected to the ProxyBridge service again");
return G_SOURCE_REMOVE;
@@ -618,6 +621,7 @@ static gboolean service_lost_idle(gpointer data) {
if (reconnect_source) return G_SOURCE_REMOVE;
gtk_statusbar_push(GTK_STATUSBAR(status_bar), status_context_id, "Lost the connection to the ProxyBridge service. Trying to reconnect...");
gui_log("lost the connection to the ProxyBridge service; trying to reconnect");
+ resume_engine = engine_state == ENGINE_RUNNING;
set_engine_state(ENGINE_STOPPED);
reconnect_source = g_timeout_add_seconds(2, reconnect_tick, NULL);
return G_SOURCE_REMOVE;
diff --git a/Linux/tests/gui_service.sh b/Linux/tests/gui_service.sh
index 436f5b4..f65413f 100755
--- a/Linux/tests/gui_service.sh
+++ b/Linux/tests/gui_service.sh
@@ -98,6 +98,29 @@ stop_gui
sleep 1
out=$(curl -s -m 5 http://192.0.2.7/); [[ "$out" == *"hello-from-A"* ]] && ok "the service keeps routing after the window closed" || bad "routing stopped with the window: $out"
+echo "== the service restarts while a window is open"
+python3 - <<PY
+import sys; sys.path.insert(0, "$HERE")
+import pbd
+d = pbd.Daemon.connect("/run/proxybridge/ctl.sock"); d.ok("hello", "1"); d.ok("boot.set", "0")
+PY
+run_gui nobody --clear-groups
+wait_routing && ok "window started" || bad "window did not start routing"
+sleep 1
+stop_service
+out=$(curl -s -m 3 http://192.0.2.7/ 2>&1); [[ "$out" != *hello-from* ]] && ok "the service is gone: traffic is direct" || bad "still routed"
+start_service
+back=0
+for _ in $(seq 40); do out=$(curl -s -m 2 http://192.0.2.7/ 2>&1); [[ "$out" == *"hello-from-A"* ]] && { back=1; break; }; sleep 0.5; done
+[ $back = 1 ] && ok "the open window reconnected, sent its rules again and restarted the engine" || bad "routing did not come back after the service restarted"
+kill -0 $GUI_PID 2>/dev/null && ok "the window stayed open throughout" || bad "the window died"
+stop_gui
+python3 - <<PY
+import sys; sys.path.insert(0, "$HERE")
+import pbd
+d = pbd.Daemon.connect("/run/proxybridge/ctl.sock"); d.ok("hello", "1"); d.ok("boot.set", "1")
+PY
+
echo "== the service restarts: a fresh service applies the profile by itself"
stop_service
out=$(curl -s -m 3 http://192.0.2.7/ 2>&1); [[ "$out" != *hello-from* ]] && ok "stopping the service ends routing (fail-open)" || bad "routed with no service"