Skip to content

Commit

Permalink
[api]: Restore Thread interrupt status on catch
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Oct 15, 2024
1 parent d32c2b8 commit f256f08
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AlpacaDiscoveryProtocol : Runnable, AutoCloseable {
val message = DatagramPacket(discoveryMessage, discoveryMessage.size, address.broadcast, 32227)
socket.send(message)
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
break
} catch (e: IOException) {
LOG.e("socket IPv4 send error", e)
Expand All @@ -58,6 +59,7 @@ class AlpacaDiscoveryProtocol : Runnable, AutoCloseable {
}
}
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
} catch (e: SocketException) {
LOG.e("socket error", e)
}
Expand All @@ -66,6 +68,7 @@ class AlpacaDiscoveryProtocol : Runnable, AutoCloseable {
val message = DatagramPacket(discoveryMessage, discoveryMessage.size, InetAddress.getByName("ff12::00a1:9aca"), 32227)
socket.send(message)
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
} catch (e: IOException) {
LOG.e("socket IPv6 send error", e)
}
Expand All @@ -78,6 +81,7 @@ class AlpacaDiscoveryProtocol : Runnable, AutoCloseable {
try {
socket.receive(packet)
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
break
} catch (e: IOException) {
LOG.e("socket receive error", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class PHD2Guider(private val client: PHD2Client) : Guider, PHD2EventListener {
try {
settling.await(settleTimeout)
} catch (_: InterruptedException) {
Thread.currentThread().interrupt()
LOG.dw("PHD2 did not send SettleDone message in expected time")
} catch (e: Throwable) {
LOG.e("an error occurrs while waiting for settle done", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class INDIProtocolReader(
listeners.onEach { it.onConnectionClosed() }.clear()
parser.close()
} catch (_: InterruptedException) {
currentThread().interrupt()
running = false
} catch (e: Throwable) {
running = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class CommandLine internal constructor(
inputReader?.waitFor()
errorReader?.waitFor()
}
} catch (ignored: InterruptedException) {
} catch (_: InterruptedException) {
currentThread().interrupt()
} finally {
if (process.isAlive) {
process.destroyForcibly()
Expand All @@ -160,10 +161,7 @@ class CommandLine internal constructor(
}
}

private inner class StreamLineReader(
stream: InputStream,
private val isError: Boolean,
) : Thread("Command Line ${if (isError) "Error" else "Input"} Stream Line Reader") {
private inner class StreamLineReader(stream: InputStream, isError: Boolean) : Thread("Command Line ${if (isError) "Error" else "Input"} Stream Line Reader") {

private val reader = stream.bufferedReader()
private val completable = CompletableFuture<Unit>()
Expand All @@ -182,6 +180,7 @@ class CommandLine internal constructor(
}
}
} catch (e: InterruptedException) {
currentThread().interrupt()
LOG.dw("command line interrupted")
} catch (e: Throwable) {
LOG.dw("command line exited: {}", e.message)
Expand Down

0 comments on commit f256f08

Please sign in to comment.