From 4d8a6a296aa2875104197da427bc4272d504ae1b Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Mon, 7 Aug 2023 22:38:06 +0530 Subject: [PATCH] fix(logsender): do not log SocktException when manually closing LogSenderHandler (#1183) --- .../itsaky/androidide/services/log/LogSenderHandler.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/itsaky/androidide/services/log/LogSenderHandler.kt b/app/src/main/java/com/itsaky/androidide/services/log/LogSenderHandler.kt index 5e6115766e..66281741b7 100644 --- a/app/src/main/java/com/itsaky/androidide/services/log/LogSenderHandler.kt +++ b/app/src/main/java/com/itsaky/androidide/services/log/LogSenderHandler.kt @@ -35,6 +35,7 @@ class LogSenderHandler( internal var onClose: (String) -> Unit = {} ) : Thread("LogSenderHandler"), AutoCloseable { + private var manuallyClosed = false private val log = ILogger.newInstance("LogSenderHandler") override fun run() { @@ -45,11 +46,15 @@ class LogSenderHandler( LogLine.forLogString(reader.readLine())?.let { line -> consumer?.invoke(line) } } catch (interrupt: InterruptedException) { currentThread().interrupt() + break } } } } catch (err: SocketException) { - log.error("An error occurred while reading from socket", err) + log.error("An error occurred while reading from socket") + if (!manuallyClosed) { + log.error(err) + } } finally { close() } @@ -57,6 +62,8 @@ class LogSenderHandler( override fun close() { try { + manuallyClosed = true + if (!socket.isClosed) { log.debug("Closing log sender handler...") socket.close()