Skip to content

Commit

Permalink
Handle broken pipe errors specifically
Browse files Browse the repository at this point in the history
Since 9555d3a, a capture/encoding error
was sometimes logged on exit.
  • Loading branch information
rom1v committed Dec 4, 2024
1 parent 0e473eb commit 5c3626e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/util/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5c3626e

Please sign in to comment.