mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-06 08:00:10 +08:00
Always close netty connection if StateLoading completed with an exception
This commit is contained in:
parent
91b5a5da58
commit
e9c53eb5db
@ -39,6 +39,7 @@ internal open class NettyNetworkHandler(
|
|||||||
private val address: SocketAddress,
|
private val address: SocketAddress,
|
||||||
) : NetworkHandlerSupport(context) {
|
) : NetworkHandlerSupport(context) {
|
||||||
override fun close(cause: Throwable?) {
|
override fun close(cause: Throwable?) {
|
||||||
|
if (state == State.CLOSED) return // already
|
||||||
setState { StateClosed(CancellationException("Closed manually.", cause)) }
|
setState { StateClosed(CancellationException("Closed manually.", cause)) }
|
||||||
super.close(cause)
|
super.close(cause)
|
||||||
// wrap an exception, more stacktrace information
|
// wrap an exception, more stacktrace information
|
||||||
@ -310,9 +311,8 @@ internal open class NettyNetworkHandler(
|
|||||||
) : NettyState(State.LOADING) {
|
) : NettyState(State.LOADING) {
|
||||||
init {
|
init {
|
||||||
coroutineContext.job.invokeOnCompletion {
|
coroutineContext.job.invokeOnCompletion {
|
||||||
if (it != null && it !is CancellationException && it !is StateSwitchingException) {
|
if (it != null) {
|
||||||
connection.close()
|
connection.close()
|
||||||
setState { StateClosed(it) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user