Fix NPE in StateConnecting

This commit is contained in:
Karlatemp 2021-05-03 11:57:50 +08:00 committed by Him188
parent b53e546743
commit 361304b9f2

View File

@ -217,11 +217,15 @@ internal open class NettyNetworkHandler(
createConnection(decodePipeline) createConnection(decodePipeline)
} }
private val connectResult = async { @Suppress("JoinDeclarationAndAssignment")
connection.join() private val connectResult: Deferred<Unit>
context[SsoProcessor].login(this@NettyNetworkHandler)
}.apply { init {
invokeOnCompletion { error -> connectResult = async {
connection.join()
context[SsoProcessor].login(this@NettyNetworkHandler)
}
connectResult.invokeOnCompletion { error ->
if (error == null) { if (error == null) {
this@NettyNetworkHandler.launch { resumeConnection() } this@NettyNetworkHandler.launch { resumeConnection() }
} else { } else {
@ -238,6 +242,7 @@ internal open class NettyNetworkHandler(
} }
// and this error will also be thrown by `StateConnecting.resumeConnection` // and this error will also be thrown by `StateConnecting.resumeConnection`
} }
} }
override fun getCause(): Throwable? = collectiveExceptions.getLast() override fun getCause(): Throwable? = collectiveExceptions.getLast()