Always close netty connection if StateLoading completed with an exception

This commit is contained in:
Him188 2021-06-06 16:56:19 +08:00
parent 91b5a5da58
commit e9c53eb5db

View File

@ -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) }
}
}
}