delblanco
05/26/2020, 1:00 PMensureNeverFrozen()
does not generate an exception or not caught on ios?Artyom Degtyarev [JB]
05/26/2020, 1:03 PMdelblanco
05/26/2020, 1:04 PMensureNeverFrozen()
seams to cancel my coroutine execution.delblanco
05/26/2020, 1:16 PMkpgalligan
05/26/2020, 1:43 PMensureNeverFrozen()
will prevent objects from freezing, but if that happens while coroutines is doing something internal, coroutines may stop and you won’t get an exception. I have seen this. Sometimes you’ll get a log about “machinery”. If you see that, it’s definitely inside the coroutines. I suspect some of the internals of coroutines are not prepared for the kinds of exceptions that come from ensureNeverFrozen()
, as previously you couldn’t get exceptions in that way unless it was something like OOM.kpgalligan
05/26/2020, 1:43 PMdelblanco
05/26/2020, 1:50 PMdelblanco
05/26/2020, 1:51 PMkpgalligan
05/26/2020, 2:05 PMinit {
//ensureNeverFrozen()
}
kpgalligan
05/26/2020, 2:05 PMdelblanco
05/26/2020, 2:05 PMensureNeverFrozen()
to the presenters init
it just stops working as my output is
launched -- this.isFrozen:falsefrom line 21
kpgalligan
05/26/2020, 2:05 PMval contentFromNetwork = withContext(<http://CoroutineContextProvider.IO|CoroutineContextProvider.IO>) {
// interactor causes this to freeze
interactor.getContent()
}
kpgalligan
05/26/2020, 2:10 PMkpgalligan
05/26/2020, 2:11 PMensureNeverFrozen()
is called before the lambdadelblanco
05/26/2020, 2:17 PMensureNeverFrozen
. In any case I'd rather have the FreezingException
compared to the silent failure.delblanco
05/26/2020, 2:19 PMval contentFromNetwork: List<Content> = try {
withContext(Dispatchers.Default) {
// interactor causes this to freeze
interactor.getContent()
}
} catch (t: Throwable) {
printThrowable(t)
emptyList()
}
delblanco
05/26/2020, 2:20 PMlaunched -- this.isFrozen:false
kotlin.native.concurrent.FreezingException: freezing of kotlinx.coroutines.$startCoroutine$lambda-0$FUNCTION_REFERENCE$30@15583c8 has failed, first blocker is common.presentation.content.TestPresenter@1d8948
kpgalligan
05/26/2020, 2:21 PMfirst blocker is common.presentation.content.TestPresenter
It’s trying to freeze TestPresenterdelblanco
05/26/2020, 2:30 PMTestPresenter
.
I expected ensureNeverFrozen()
to throw an exception in the original snippet when the freeze was happening. Instead of an exception being thrown ... the coroutine stopped working without any indication.delblanco
05/26/2020, 2:44 PMthis
got accidentally frozen is a tedious task ... which I don't like to repeat or have to sell to my iOS colleagueskpgalligan
05/26/2020, 5:33 PMwithContext
and similar methods I think need to be modified for the case where something fails. In the JVM version, I don’t think anything would normally fail. Internally, it’s just moving state between threads. In native, the internal coroutines code doesn’t expect that to fail and apparently doesn’t throw properlykpgalligan
05/26/2020, 5:34 PMlittering the code with log statements to find where this got accidentally frozen is a tedious task
Agree. Updating coroutines to throw when ensureNeverFrozen()
fails should help that case significantly. I also built an intellij plugin to warn you about trapping state like that, but we’re not sure yet if it’s going to be released. In this case it definitely would’ve warned you.delblanco
05/27/2020, 7:57 AMdelblanco
05/27/2020, 10:03 AMphldavies
05/27/2020, 3:57 PM