From e9c53eb5db08d9752b14c3f04d300a778fe7d0a2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 6 Jun 2021 16:56:19 +0800 Subject: [PATCH] Always close netty connection if StateLoading completed with an exception --- .../kotlin/network/impl/netty/NettyNetworkHandler.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt index d0ba85c64..44508dc0a 100644 --- a/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt +++ b/mirai-core/src/commonMain/kotlin/network/impl/netty/NettyNetworkHandler.kt @@ -39,6 +39,7 @@ internal open class NettyNetworkHandler( private val address: SocketAddress, ) : NetworkHandlerSupport(context) { override fun close(cause: Throwable?) { + if (state == State.CLOSED) return // already setState { StateClosed(CancellationException("Closed manually.", cause)) } super.close(cause) // wrap an exception, more stacktrace information @@ -310,9 +311,8 @@ internal open class NettyNetworkHandler( ) : NettyState(State.LOADING) { init { coroutineContext.job.invokeOnCompletion { - if (it != null && it !is CancellationException && it !is StateSwitchingException) { + if (it != null) { connection.close() - setState { StateClosed(it) } } } }