Fix endless reconnection on LoginFailedException, close #895

This commit is contained in:
Him188 2021-01-25 12:41:07 +08:00
parent ff9cc6a74e
commit af9eadf34e

View File

@ -163,7 +163,6 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
private inner class Reconnect {
suspend fun reconnect(event: BotOfflineEvent): Boolean {
while (true) {
retryCatchingExceptions<Unit>(
configuration.reconnectionRetryTimes,
except = LoginFailedException::class
@ -193,16 +192,17 @@ internal abstract class AbstractBot<N : BotNetworkHandler> constructor(
}.getOrElse { exception ->
if (exception is LoginFailedException && !exception.killBot) {
logger.info { "Cannot reconnect." }
logger.warning(exception)
logger.info { "Retrying in 3s..." }
delay(3000)
return@getOrElse
}
logger.info { "Cannot reconnect due to fatal error." }
bot.cancel(CancellationException("Cannot reconnect due to fatal error.", exception))
logger.error(exception)
// logger.info { "Retrying in 3s..." }
// delay(3000)
return false
}
logger.info { "Cannot reconnect." }
bot.cancel(CancellationException("Cannot reconnect.", exception))
return false
}
return false
}
}