From 6aa321971e258cd0970b8f95742bf1c7cfe293ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=D0=B5=20=D0=98=D0=BC=D1=8F?= Date: Sun, 8 Jun 2025 04:16:54 +0700 Subject: [PATCH] Fix TCP socket finishConnect() exception handling and connection logic - Fix bug where finishConnect() required multiple calls before throwing exceptions - Fix logic where address resolution didn't immediately attempt connection - After address is resolved, immediately call channel.finishConnect() - Ensures immediate error reporting for failed socket connections - Improves reliability of socket connection error handling --- .../scala/li/cil/oc/server/component/InternetCard.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/InternetCard.scala b/src/main/scala/li/cil/oc/server/component/InternetCard.scala index a13c8912d..b6d2a9551 100644 --- a/src/main/scala/li/cil/oc/server/component/InternetCard.scala +++ b/src/main/scala/li/cil/oc/server/component/InternetCard.scala @@ -329,7 +329,9 @@ object InternetCard { private def checkConnected() = { if (owner.isEmpty) throw new IOException("connection lost") try { - if (isAddressResolved) channel.finishConnect() + if (isAddressResolved) { + channel.finishConnect() + } else if (address.isCancelled) { // I don't think this can ever happen, Justin Case. channel.close() @@ -341,14 +343,15 @@ object InternetCard { case e: ExecutionException => throw e.getCause } isAddressResolved = true - false + // After address resolution, immediately attempt connection + channel.finishConnect() } else false } catch { case t: Throwable => close() - false + throw t // Propagate exception instead of returning false } }