Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(connect): stop the client loop when poll mode learns of revocation

Juan Denis386cd6aa3a6c
diff --git a/backend/app/services/connect_client.py b/backend/app/services/connect_client.py
index 0dde9505..48d83142 100644
--- a/backend/app/services/connect_client.py
+++ b/backend/app/services/connect_client.py
@@ -766,7 +766,14 @@ class RelayClient:
return
if time.monotonic() < ws_blocked_until:
- if self._poll_session(cfg, ws_blocked_until) == 'stopped':
+ outcome = self._poll_session(cfg, ws_blocked_until)
+ if outcome == 'stopped':
+ return
+ if outcome == 'revoked':
+ # Same terminal handling as the ws path: limited mode is
+ # where a panel behind a code-stripping edge learns it.
+ self._set_state('revoked', 'revoked', transport=None)
+ logger.warning('Connect relay: device revoked on ServerKit Cloud; stopping')
return
ws_blocked_until = 0.0 # time to re-probe WS
continue
diff --git a/backend/tests/BASELINE_COUNT b/backend/tests/BASELINE_COUNT
index 8d3ce569..844039bc 100644
--- a/backend/tests/BASELINE_COUNT
+++ b/backend/tests/BASELINE_COUNT
@@ -1 +1 @@
-5278
+5279
diff --git a/backend/tests/test_connect_relay.py b/backend/tests/test_connect_relay.py
index d653c332..f5540c6f 100644
--- a/backend/tests/test_connect_relay.py
+++ b/backend/tests/test_connect_relay.py
@@ -439,3 +439,19 @@ def test_a_revoked_frame_mid_session_ends_it_as_revoked(monkeypatch):
'_publish_policy', '_publish_inventory'):
monkeypatch.setattr(client, name, lambda *args: None)
assert client._ws_session({}) == 'revoked'
+
+
+def test_revocation_seen_in_poll_mode_stops_the_loop(config_dir, monkeypatch):
+ """_poll_session reports 'revoked'; the loop must write the state and stop,
+ not fall through and re-probe the websocket forever (the 2026-09-12 lab
+ run: a panel behind the code-stripping edge never observed revocation)."""
+ _fake_config(monkeypatch)
+ monkeypatch.setattr(connect_client.RelayClient, '_ws_session',
+ lambda self, cfg: 'refused:relay_unreachable')
+ monkeypatch.setattr(connect_client.RelayClient, '_poll_session',
+ lambda self, cfg, retry_at: 'revoked')
+ client = connect_client.RelayClient()
+ client.start()
+ client._thread.join(timeout=5)
+ assert not client._thread.is_alive()
+ assert connect_client._read_state_file()['state'] == 'revoked'