Handle broken pipe errors specifically

Since 9555d3a537a828731ad89ef5258ba537acf8cc11, a capture/encoding error
was sometimes logged on exit.
This commit is contained in:
Romain Vimont 2024-12-04 18:38:23 +01:00
parent 0e473eb005
commit 5c3626ed47
2 changed files with 8 additions and 0 deletions

View File

@ -72,4 +72,8 @@ public final class IO {
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);
}
}

View File

@ -113,6 +113,10 @@ public class SurfaceEncoder implements AsyncProcessor {
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;