Fix: Reconnect to lightwalletd when a service exception occurs.

This is a fairly frequent crash that occurs when devices return from the background and attempt to reuse a stale channel. In that situation, shutdown the stale channel and rebuild a new one.
This commit is contained in:
Kevin Gorham 2021-05-25 12:43:42 -04:00
parent 0c73f2b585
commit 84ca57f432
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 9 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package cash.z.ecc.android.sdk.block // iimport cash.z.ecc.android.sdk.exception.LightWalletException
import cash.z.ecc.android.sdk.exception.LightWalletException
import cash.z.ecc.android.sdk.ext.tryWarn
import cash.z.ecc.android.sdk.ext.twig
import cash.z.ecc.android.sdk.service.LightWalletService
import cash.z.wallet.sdk.rpc.Service
import io.grpc.StatusRuntimeException
@ -75,8 +76,14 @@ open class CompactBlockDownloader private constructor(val compactBlockStore: Com
compactBlockStore.getLatestHeight()
}
suspend fun getServerInfo(): Service.LightdInfo = withContext(IO) {
lightWalletService.getServerInfo()
suspend fun getServerInfo(): Service.LightdInfo = withContext<Service.LightdInfo>(IO) {
try {
lightWalletService.getServerInfo()
} catch (e: StatusRuntimeException) {
twig("WARNING: reconnecting to service in response to failure: $e")
lightWalletService.reconnect()
lightWalletService.getServerInfo()
}
}
suspend fun changeService(