Set state to CLOSED on failure during connecting

This commit is contained in:
Him188 2021-04-27 21:48:05 +08:00
parent 23b296692e
commit b62e39b4d1

View File

@ -229,10 +229,11 @@ internal open class NettyNetworkHandler(
return@invokeOnCompletion // already been switching to CONNECTING
}
setState(null) { // ignore replication check
StateConnecting(
collectiveExceptions.apply { collect(error) },
wait = true
)
// StateConnecting(
// collectiveExceptions.apply { collect(error) },
// wait = true
// )
StateClosed(collectiveExceptions.collectGet(error))
} // logon failure closes the network handler.
}
// and this error will also be thrown by `StateConnecting.resumeConnection`
@ -265,6 +266,15 @@ internal open class NettyNetworkHandler(
protected inner class StateLoading(
private val connection: NettyChannel
) : NettyState(State.LOADING) {
init {
coroutineContext.job.invokeOnCompletion {
if (it != null && it !is CancellationException && it !is StateSwitchingException) {
connection.close()
setState { StateClosed(it) }
}
}
}
override suspend fun sendPacketImpl(packet: OutgoingPacket): Boolean {
connection.writeAndFlush(packet)
return true