From 9c08eb79cb7941848882cb908cefee9933450de5 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 9 Apr 2023 19:12:39 +0200 Subject: [PATCH] Close connection at the end of finally-block The async processors use the socket file descriptors from the connection. Therefore, the connection must not be closed before all async processor threads are joined. PR #3978 --- server/src/main/java/com/genymobile/scrcpy/Server.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 067b1670..fade7214 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -92,7 +92,8 @@ public final class Server { List asyncProcessors = new ArrayList<>(); - try (DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte)) { + DesktopConnection connection = DesktopConnection.open(scid, tunnelForward, audio, control, sendDummyByte); + try { if (options.getSendDeviceMeta()) { connection.sendDeviceMeta(Device.getDeviceName()); } @@ -150,6 +151,8 @@ public final class Server { } catch (InterruptedException e) { // ignore } + + connection.close(); } }