diff --git a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java index 03b80342a..650742201 100644 --- a/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java +++ b/app/src/main/java/io/xpipe/app/beacon/impl/TerminalLaunchExchangeImpl.java @@ -2,13 +2,14 @@ package io.xpipe.app.beacon.impl; import io.xpipe.app.terminal.TerminalLauncherManager; import io.xpipe.beacon.BeaconClientException; +import io.xpipe.beacon.BeaconServerException; import io.xpipe.beacon.api.TerminalLaunchExchange; import com.sun.net.httpserver.HttpExchange; public class TerminalLaunchExchangeImpl extends TerminalLaunchExchange { @Override - public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException { + public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException { var r = TerminalLauncherManager.launchExchange(msg.getRequest()); return Response.builder().targetFile(r).build(); } diff --git a/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java b/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java index babe7515d..8f9ba1b42 100644 --- a/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java +++ b/app/src/main/java/io/xpipe/app/terminal/TerminalLauncherManager.java @@ -2,6 +2,7 @@ package io.xpipe.app.terminal; import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.ext.ShellStore; +import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.storage.DataStoreEntryRef; import io.xpipe.app.util.LocalShell; import io.xpipe.app.util.SecretManager; @@ -77,7 +78,7 @@ public class TerminalLauncherManager { req = entries.get(request); } if (req == null) { - throw new BeaconClientException("Unknown launch request " + request); + return; } var byPid = ProcessHandle.of(pid); if (byPid.isEmpty()) { @@ -90,33 +91,44 @@ public class TerminalLauncherManager { req.setPid(shell.pid()); } - public static Path waitExchange(UUID request) throws BeaconClientException, BeaconServerException { + public static void waitExchange(UUID request) throws BeaconClientException, BeaconServerException { TerminalLaunchRequest req; synchronized (entries) { req = entries.get(request); } if (req == null) { - throw new BeaconClientException("Unknown launch request " + request); + return; } if (req.isSetupCompleted()) { submitAsync(req.getRequest(), req.getProcessControl(), req.getConfig(), req.getWorkingDirectory()); } try { - return req.waitForCompletion(); + req.waitForCompletion(); } finally { req.setSetupCompleted(true); } } - public static Path launchExchange(UUID request) throws BeaconClientException { + public static Path launchExchange(UUID request) throws BeaconClientException, BeaconServerException { synchronized (entries) { var e = entries.values().stream() .filter(entry -> entry.getRequest().equals(request)) .findFirst() .orElse(null); if (e == null) { - throw new BeaconClientException("Unknown launch request " + request); + // It seems like that some terminals might enter a restart loop to try to start an older process again + // This would spam XPipe continuously with launch requests if we returned an error here + // Therefore, we just return a new local shell session + TrackEvent.withTrace("Unknown launch request").tag("request", request.toString()).handle(); + try (var sc = LocalShell.getShell().start()) { + var defaultShell = ProcessControlProvider.get().getEffectiveLocalDialect(); + var shellExec = defaultShell.getExecutableName(); + var absExec = sc.view().findProgram(shellExec).orElse(shellExec); + return Path.of(absExec); + } catch (Exception ex) { + throw new BeaconServerException(ex); + } } if (!(e.getResult() instanceof TerminalLaunchResult.ResultSuccess)) { diff --git a/version b/version index edf645a3b..81ba0db56 100644 --- a/version +++ b/version @@ -1 +1 @@ -15.4-2 +15.4-3