From 209ac4d749e97dd1e6a8fc68fa3e49a4cfaac1fe Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 16 Aug 2026 22:01:59 +1000 Subject: [PATCH] [client] spice: gate USB reconnect on MAIN health --- client/transports/SPICE/usbredir.c | 29 +++++++++++++++++++++++++++++ repos/PureSpice | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/client/transports/SPICE/usbredir.c b/client/transports/SPICE/usbredir.c index 433c9629..18cc65dc 100644 --- a/client/transports/SPICE/usbredir.c +++ b/client/transports/SPICE/usbredir.c @@ -55,6 +55,8 @@ struct LG_USBRedir bool disconnectPending; int64_t disconnectDeadline; int64_t reconnectDeadline; + uint64_t mainPingCount; + bool waitingForMainPing; }; static void setAvailable(LG_USBRedir * usbredir, bool available) @@ -192,6 +194,25 @@ static bool selectChannel(LG_USBRedir * usbredir) if (usbredir->channel) return true; + if (!purespice_channelConnected(PS_CHANNEL_MAIN)) + { + usbredir->reconnectDeadline = + (int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS; + return false; + } + + if (usbredir->waitingForMainPing) + { + if (purespice_mainPingCount() == usbredir->mainPingCount) + { + usbredir->reconnectDeadline = + (int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS; + return false; + } + + usbredir->waitingForMainPing = false; + } + for (unsigned int i = 0; i < USB_REDIR_CHANNEL_COUNT; ++i) { PSUSBRedirChannel * channel = usbredir->channels[i]; @@ -424,8 +445,16 @@ void lgUsbRedir_state(PSUSBRedirChannel * channel, destroyParser(usbredir); usbredir->channel = NULL; if (purespice_usbRedirAvailable(channel)) + { + /* Wait for a fresh MAIN PING/PONG before reconnecting this + * optional channel. The server shuts it down before MAIN during a + * session teardown, so this prevents reconnect attempts to a + * disappearing SPICE server. */ + usbredir->mainPingCount = purespice_mainPingCount(); + usbredir->waitingForMainPing = true; usbredir->reconnectDeadline = (int64_t)nanotime() + USB_REDIR_RECONNECT_DELAY_NS; + } } break; diff --git a/repos/PureSpice b/repos/PureSpice index 1c0b0820..e324456a 160000 --- a/repos/PureSpice +++ b/repos/PureSpice @@ -1 +1 @@ -Subproject commit 1c0b08204ba614c861f1e253293b065cfb2093dd +Subproject commit e324456ab5937d0b0aedc7ab3247566c8d5711f3