appmattus/certificatetransparency

Intercepting network request causing InterruptedException when using RxJava approach

Closed this issue · 1 comments

Hey guys,
I'm facing java.lang.InterruptedException
Crash stack trace - ExceptionStacktrace.txt
I'm making a network request using RxJava on one of my app's screen (show details fragment for example)
val subscription = interactor.getData(requestDetails) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(.......) compositeSubscriptions.add(subscription)
I allow user user to leave that screen immediately after entering it.
When user leaves fragment I'm clearing all my subscriptions:
override fun onDestroy() { compositeSubscriptions.clear() .... }
Sometimes user may leave the screen while network request is still being intercepted and it may force InterruptedException (Parent job is Cancelling).
Inside hasValidSignedCertificateTimestamp(....) you are launching a new coroutine and block current thread.
val result = runBlocking { logListDataSource.get() }
There is a small chance not to finish coroutine job until the thread where coroutine was run on, was dismissed.

Are you aware about this issue or is there any work-around for this?

Did you consider about getting rid of runBlocking {...} block? If you're not providing any context it will get run on the mainThread?

I'm not sure that CoroutineExceptionHandler is gonna solve the issue.
val handler = CoroutineExceptionHandler { _, _ -> logger?.log(host, VerificationResult.Failure.LogServersFailed(NoLogServers)) } val result = runBlocking(handler + Dispatchers.IO) { logListDataSource.get() }

but surrounding runBlocking{...} block with try/catch may help:
val result = try { runBlocking { logListDataSource.get() } } catch (e: Exception) { null }