From 386dd3b75f57d3473431e5cd1e6107f709b457c1 Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Thu, 11 May 2023 20:18:00 +0200 Subject: [PATCH] 7.2.20 Possible fix for "Read timed out" when opening any connection and AP-Web is overloaded --- .../client/network/online/DefaultConnection.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/osiris/autoplug/client/network/online/DefaultConnection.java b/src/main/java/com/osiris/autoplug/client/network/online/DefaultConnection.java index 46b0081e..0fb192b1 100644 --- a/src/main/java/com/osiris/autoplug/client/network/online/DefaultConnection.java +++ b/src/main/java/com/osiris/autoplug/client/network/online/DefaultConnection.java @@ -85,8 +85,8 @@ public synchronized void setAndStartAsync(RunnableWithException runnable) { this.thread = new Thread(() -> { try { runnable.run(); - } catch (Exception e) { - if (!isClosing.get()) AL.warn(e); // Exceptions caused by close() are ignored + } catch (Exception e) { // Exceptions caused by close() are ignored + if (!isClosing.get()) AL.warn(e); try { _close(Thread.currentThread(), _in, _out, _socket); } catch (Exception ex) { @@ -110,6 +110,7 @@ public synchronized boolean open() throws Exception { } private synchronized int _open() throws Exception { + socket.setSoTimeout(60000); isClosing.set(false); errorCode = 0; close(); @@ -143,12 +144,8 @@ private synchronized int _open() throws Exception { } AL.debug(this.getClass(), "[CON_TYPE: " + conType + "] Authenticating server with Server-Key..."); - socket.setSoTimeout(30000); out.writeUTF(serverKey); // Send server key out.writeByte(conType); // Send connection type - socket.setSoTimeout(5000); - - this.errorCode = in.readByte(); // Get response return errorCode; } @@ -285,7 +282,7 @@ private void _close(Thread thread, InputStream in, OutputStream out, Socket sock if (in != null) in.close(); if (out != null) out.close(); if (socket != null) socket.close(); - if (thread != null) thread.interrupt(); + if (thread != null) thread.interrupt(); // Close thread last, since it might be the current thread } @Override