Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatchers.IO coroutine is blocked by load on Main #3038

Closed
permiakover opened this issue Nov 23, 2021 · 13 comments
Closed

Dispatchers.IO coroutine is blocked by load on Main #3038

permiakover opened this issue Nov 23, 2021 · 13 comments

Comments

@permiakover
Copy link

Hello, I'm trying to solve the incident. Some coroutine in IO dispatcher reads data from device, but if main thread got a lot of work to redraw - the IO coroutine will be blocked for the delay. on JVM 11
The device-reading coroutine works in DefaultDispatcher-worker-*

@dkhalanskyjb
Copy link
Collaborator

See the workaround here: #2972 (comment)

@permiakover
Copy link
Author

also it's for JavaFX coroutines

@dkhalanskyjb
Copy link
Collaborator

Doesn't matter. The issue and the workaround are the same for any Dispatchers.Main implementation.

@permiakover
Copy link
Author

So i need to set the flag "kotlinx.coroutines.main.delay" - where I can set it?

@dkhalanskyjb
Copy link
Collaborator

It is a system property: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_system_properties

Even though the workaround should fix this for you, could you please answer some questions to help us design the library?

  • What are you doing in Dispatchers.IO while the application is busy with drawing?
  • What was the debugging process by which you reached the conclusion that "many redraws → the delay hangs"?

Context: in the latest release candidate, we've made it so Dispatchers.Main is used to execute delay, if possible, so we're interested in which problems this may cause, and how difficult it is to find the root of these problems.

@permiakover
Copy link
Author

permiakover commented Nov 23, 2021

No the workaround doesn't work for me. even using 1.6.0-RC lib version
I have a JavaFx application, which reads data from device (early with a java thread executor, now with CorotineScope(Dispatchers.IO). I'm logging the reading interval (in my case 10 ms), and I discover a huge lag (100-200 ms) caused by JavaFx Thread Load

@dkhalanskyjb
Copy link
Collaborator

dkhalanskyjb commented Nov 23, 2021

No the workaround doesn't work for me

What exactly are you doing?
System.setProperty("kotlinx.coroutines.main.delay", "false") at the start of the application, before doing anything with the coroutines, should work.

reads data from device

I see, thanks! What is the purpose of the delay there?

@permiakover
Copy link
Author

object Main {
    @JvmStatic
    fun main(args: Array<String>) {
        System.setProperty("kotlinx.coroutines.main.delay", "false")
        FeatureProcedureView.main(args)
    }
}

I start JavaFX app this way, also add setProperty to the di objects. Anyway I got the same behavior.

I don't use delay, the delay comes from blocking method of device reading library, that uses JNI methods

@dkhalanskyjb
Copy link
Collaborator

Oh. In this case, maybe this issue is actually unrelated to #2972.

A question I probably should've asked first: did the issue start happening after updating 1.6.0-RC or did it happen before as well?

@permiakover
Copy link
Author

yes, first I discovered it using 'kotlinx-coroutines-javafx', version: '1.5.2'

@dkhalanskyjb
Copy link
Collaborator

Ok, then the workaround I suggested definitely won't work.

Did you ever see the good behavior in this case, or was the issue always present?
Also, it may be difficult to diagnose without a reproducing project—could you provide the source code of a project where this happens?

@permiakover
Copy link
Author

My project is NDA, but I will prepare a project that will reproduce this behavior, but it requires custom HID device, not keyboard or mouse. Need some time to make a proper mock

@qwwdfsad
Copy link
Member

Closing as obsolete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants