I’ve got a new crash on ios in Kotlin 1.3.70 in co...
# kotlin-native
r
I’ve got a new crash on ios in Kotlin 1.3.70 in coroutines. Here is the top of the stack
And then 1.5k lines later, this
@basher I don’t know if it’s related to the usage of CoroutineWorker or not
Here is how I use CoroutineWorker. I have multiple instances of this class (somewhere between 4 and 10). Most of the time
executeJobs()
does nothing (basically a
forEach
on a Stately
sharedMutableList()
which is empty most of the time)
The crash occurs after some minutes of execution of the app
b
hard to tell exactly. might be the delay usage in CoroutineWorker now overflows the stack
can i see the implementation of executeJobs?
r
In this case it handles file jobs
Copy code
private fun executeJobs() {
        if (queue.isEmpty()) return
        val jobs = queue.toList()
        jobs.forEach { job ->
            when (job) {
                is WriteJob -> {
                    try {
                        job.file.writeRaw(job.content, create = true, createParents = true)
                    } catch (t: Throwable) {
                        log.error("Failed to write file ${job.file}: ${t.message}", t)
                    }
                }
                is DeleteJob -> {
                    try {
                        job.file.delete()
                    } catch (t: Throwable) {
                        log.error("Failed to delete file ${job.file}: ${t.message}", t)
                    }
                }
            }
        }
        queue.removeAll(jobs)
    }
At first I wanted to have a single
CoroutineWorker.execute
per instance which would run an infinite loop waiting on a shared collection, but CoroutineWorker is hardcoded to 4 threads and I need more than 4 and it was deadlocking somehow (I thought that using
delay
would allow a different execute block to continue execution but it didn’t work)
But in the end this solution worked well in 1.3.61 and now this
b
Is there any way you can provide a sample project and file an issue? At this point, I don't think there's much I can do on slack. Issue seems quite complex. Even if the sample project just runs the crashing code in a unit test, that would be helpful
An issue to allow setting the number of threads would be good too. That wouldn't be hard to add
Even if you can't make a sample project, moving to GH is prob best
r
I just have no way to know where this comes from for sure, it may as well be a bug in coroutines 1.3.4/1.3.5 or in my code, I don’t know. It will be very hard to make a reproducer I think but I’ll try if I have the time at some point. For now due to this issue and others I need to rollback to 1.3.61 to be able to work at all. Maybe once this issue is the only one preventing me from updating Kotlin I’ll try
b
Sounds good! No rush. If Kotlin 1.3.71 is followed by the kotlinx.coroutines native multithreading mpp release (as is expected), coroutineworker will become deprecated (just a heads up)
r
Yes, I’m really waiting for this, but I’m not expecting something this big to be very stable at first either