From 5c3626ed47b983625481f852073cef859e7fcaf9 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 4 Dec 2024 18:38:23 +0100 Subject: [PATCH] Handle broken pipe errors specifically Since 9555d3a537a828731ad89ef5258ba537acf8cc11, a capture/encoding error was sometimes logged on exit. --- server/src/main/java/com/genymobile/scrcpy/util/IO.java | 4 ++++ .../main/java/com/genymobile/scrcpy/video/SurfaceEncoder.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/server/src/main/java/com/genymobile/scrcpy/util/IO.java b/server/src/main/java/com/genymobile/scrcpy/util/IO.java index b953f290b4..16ddaedde3 100644 --- a/server/src/main/java/com/genymobile/scrcpy/util/IO.java +++ b/server/src/main/java/com/genymobile/scrcpy/util/IO.java @@ -72,4 +72,8 @@ public static boolean isBrokenPipe(IOException e) { Throwable cause = e.getCause(); return cause instanceof ErrnoException && ((ErrnoException) cause).errno == OsConstants.EPIPE; } + + public static boolean isBrokenPipe(Exception e) { + return e instanceof IOException && isBrokenPipe((IOException) e); + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceEncoder.java b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceEncoder.java index 1402eceb14..236a5f4836 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/SurfaceEncoder.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/SurfaceEncoder.java @@ -113,6 +113,10 @@ private void streamCapture() throws IOException, ConfigurationException { alive = !stopped.get() && !capture.isClosed(); } } catch (IllegalStateException | IllegalArgumentException | IOException e) { + if (IO.isBrokenPipe(e)) { + // Do not retry on broken pipe, which is expected on close because the socket is closed by the client + throw e; + } Ln.e("Capture/encoding error: " + e.getClass().getName() + ": " + e.getMessage()); if (!prepareRetry(size)) { throw e;