question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m trying to track down a freezing issue on iOS when using reaktive streams, and pared down the issue with a new sample project.

It seems the call to mutate() below is causing ShimTester to be frozen, but I thought using threadLocal would prevent that. Is my current usage correct? What’s the correct way to call mutate() in the example below?

KN code:


class ShimTester {

    init {
        expectEnsureNeverFrozenShim()
    }

    fun mutate() { }

    fun testApiWrapper(): ObservableWrapper<Unit> {
        return testApi()
                .subscribeOn(mainScheduler)
                .observeOn(mainScheduler)
                .threadLocal()
                .wrap()
    }

    fun testApi(): Observable<Unit> {
        return observableFromFunction {
            mutate()

            Unit
        }
    }
}

On iOS, I’m using:

        ShimTester().testApiWrapper().subscribe(
            isThreadLocal: true,
            onSubscribe: nil,
            onError: nil,
            onComplete: nil) { unit in
                print("Done")
        }

This causes an exception:

Uncaught exception: kotlin.native.concurrent.FreezingException: 
 freezing of [com.badoo.reaktive.scheduler.MainScheduler.ExecutorImpl.Operation@1e25bc8] has failed,
 first blocker is ...ShimTester@1daa928kotlin.native.concurrent.FreezingException:
 freezing of [com.badoo.reaktive.scheduler.MainScheduler.ExecutorImpl.Operation@1e25bc8] has failed,
 first blocker is ..ShimTester@1daa928

I tried moving threadLocal further upstream, before mutate(), but hit the same freeze exception:

class ShimTester {

    ...

    fun testApi(): Observable<Unit> {
        return observableOf(5)
                .subscribeOn(mainScheduler)
                .observeOn(mainScheduler)
                .threadLocal()
                .map {
                    mutate()
                    Unit
                }
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
arkivanovcommented, Jun 6, 2020

Hey, it’s hard to understand why is it frozen, the fix may help. It may be frozen by Reaktive or by SQLDelight. But in general I would not expect the listener to be not frozen, and just design the app in such a way. You can try querying database in the following way:

db
    .testQueries
    .select()
    .listenForChanges()
    .observeOn(mainScheduler)
    .subscribe(isThreadLocal = true) {
        // Use the data
    }

Or like this:

    network
        .loadData()
        .observeOn(ioScheduler)
        .doOnBeforeSuccess { 
            db.saveData(it) // Blocking call
        }
        .observeOn(mainScheduler)
        .subscribe(isThreadLocal = true) {
            // Use the data
        }    

You can find some useful SQLDelight extensions here.

Please note, I did not try yet the provided code above in Kotlin/Native. But it should work assuming SQLDelight is freezable (unlike Ktor). I hope it is freezable.

1reaction
arkivanovcommented, May 31, 2020

Actually there is a bug. The following code should work but it crashes in iOS:

class ShimTester {

    init {
        ensureNeverFrozen()
    }

    fun mutate() {
    }

    fun testApi() {
        observableOf(5)
            .filter { true }
            .map {
                mutate()
                Unit
            }
            .observeOn(mainScheduler)
            .subscribe()
    }
}

I will fix this. Thanks for raising the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Fix Computer Freezing - Driver Easy
Fixes for computer freezing · Update your drivers · Adjust power plan settings for your hard disk · Delete the temp files ·...
Read more >
6 Methods to Solve Computer Keeps Freezing (#5 Is Awesome)
Computer keeps freezing? This page tells you how to effectively fix the Windows keeps freezing issue with ease.
Read more >
Windows-based computer freeze troubleshooting
This article describes how to troubleshoot freeze issues on Windows-based computers and servers. It also provides methods for collecting ...
Read more >
Fix an Android device that freezes or won't respond
Try the following steps if your phone: Freezes Stops responding Is stuck with the screen on After each step, restart your phone to...
Read more >
Tips for Random System Freezing Issue - Intel
Provides useful tips to try with Random System Freezing Issue. ... Motherboard issues: If possible, swap with a good working motherboard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found