From 4dbeb5bba86b0a0622f3fd2b6c2a31e1fde55e79 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 10 Jul 2025 17:18:23 +0000 Subject: [PATCH] Fix app running check [stage] --- .../java/io/xpipe/beacon/BeaconServer.java | 19 ++++++++++++++++--- dist/changelogs/17.0.md | 1 + version | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index d2feb8b37..c0e7bd5e7 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -5,11 +5,13 @@ import io.xpipe.core.FilePath; import io.xpipe.core.OsType; import io.xpipe.core.XPipeDaemonMode; import io.xpipe.core.XPipeInstallation; +import lombok.SneakyThrows; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.Inet4Address; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.net.Socket; import java.util.List; @@ -18,14 +20,25 @@ import java.util.List; */ public class BeaconServer { + @SneakyThrows public static boolean isReachable(int port) { + var local = Inet4Address.getByAddress(new byte[]{0x7f, 0x00, 0x00, 0x01}); + try (var socket = new Socket()) { - socket.connect( - new InetSocketAddress(Inet4Address.getByAddress(new byte[] {0x7f, 0x00, 0x00, 0x01}), port), 5000); - return true; + InetSocketAddress adress = new InetSocketAddress(local, port); + socket.connect(adress, 5000); } catch (Exception e) { return false; } + + // If there's some kind of networking tool interfering with sockets by for example proxying socket connections + // The previous connect might succeed even though nothing is running. + // To be sure, check that the socket is indeed occupied + try (var ignored = new ServerSocket(port, 0, local)) { + return false; + } catch (Exception e) { + return true; + } } private static List toProcessCommand(String toExec) { diff --git a/dist/changelogs/17.0.md b/dist/changelogs/17.0.md index 726d08107..b89da15d6 100644 --- a/dist/changelogs/17.0.md +++ b/dist/changelogs/17.0.md @@ -145,3 +145,4 @@ The HTTP API has been improved in various areas. The action system is integrated - Fix text color on hover having low contrast in some themes - Fix connection search freezing on Ubuntu systems with LXD snap stub installed - Fix freeze after waking up the local system from a long hibernation +- Fix application not starting up if some antivirus interfered with local socket connections diff --git a/version b/version index 2378eee4a..04d45f9e8 100644 --- a/version +++ b/version @@ -1 +1 @@ -17.0-15 +17.0-16