Closed zachzurn closed 1 year ago
@zachzurn Can you post your device discovery code?
@gare-bear Hello, I have faced the same problem. Here is the repository with a minimal code to reproduce the issue: https://github.com/MihailYa/stario-printer-bug/tree/main
The code from the repository:
private fun launchSearchPrinters() = lifecycleScope.launch(Dispatchers.Default) {
repeat(1000) {
Log.d(TAG, "Try to reproduce ConcurrentModificationException bug #$it")
val job1 = launch {
searchPrinters()
}
delay(300)
job1.cancel()
delay(500)
}
}
private suspend fun searchPrinters(): List<StarPrinter> {
val manager = StarDeviceDiscoveryManagerFactory.create(
interfaceTypes = listOf(InterfaceType.Lan, InterfaceType.Usb),
context = applicationContext
)
manager.discoveryTime = 5000
return suspendCoroutine { cont ->
val printers = mutableListOf<StarPrinter>()
manager.callback = object : StarDeviceDiscoveryManager.Callback {
override fun onPrinterFound(printer: StarPrinter) {
printers.add(printer)
}
override fun onDiscoveryFinished() {
cont.resume(printers.toList())
}
}
manager.startDiscovery()
}
}
The code starts and stops printers search in a loop. It could take from 10 seconds to 5 minutes until the crash happens.
The device on which I'm reproducing the bug: Android 10 Samsung SM-G960U1
In the production environment, this issue also happens - the application randomly crashes when the user tries to search for the printer.
I have the same problem. The crash happens randomly on the first discovery started from the background. There are no specific conditions, regular app start in debug or release builds. The crash happens randomly and on different phones Samsung S20 FE, S21, A40, Nokia OnePlus8. Pretty annoying thing.
@MihailYa Thank you very much for providing a minimal code. I have reproduced the problem, and we are now investigating the root cause.
@zachzurn @MihailYa @alsedi Thank you for your report. We have found a problem in StarIO10. And it will be fixed in the future update. We much appreciate your patience and understanding.
@zachzurn @MihailYa @alsedi We have fixed this problem in the latest version (StarIO10 Ver.1.3.0). Again, thank you for your cooperation.
Description
I'm getting an uncaught error that is showing up in my Bugsnag production logs. I am having a hard time reproducing the issue.
java.util.ConcurrentModificationException at java.util.ArrayList$Itr.next(ArrayList.java:860) at com.starmicronics.stario10.stardevicediscoverymanager.c.a(Unknown:201) at com.starmicronics.stario10.stardevicediscoverymanager.c$a.invokeSuspend(Unknown:12) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Any idea of why this could be happening or how to prevent it?
Your device where the bug occurs
Your printer
This is happening during discovery while looking for USB, BT and LAN devices.
Your development environment
Android Studio
To Reproduce
Unable to reproduce