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

Scheduler.forkJoin stops executing tasks after reaching its maximum thread count #1588

Open
ghik opened this issue Jun 15, 2022 · 1 comment · May be fixed by #1589
Open

Scheduler.forkJoin stops executing tasks after reaching its maximum thread count #1588

ghik opened this issue Jun 15, 2022 · 1 comment · May be fixed by #1589

Comments

@ghik
Copy link
Contributor

ghik commented Jun 15, 2022

Try running this code:

implicit val scheduler: Scheduler = Scheduler.forkJoin(4, 8)

// make the pool reach its maximum thread count
Task.parTraverseUnordered(0 until 1000) { _ =>
   Task(scala.concurrent.blocking(Thread.sleep(10)))
}.runSyncUnsafe()

println("slept")

// this task never executes
Task(println("foo")).executeAsync.runSyncUnsafe()

println("done")

After the pool reaches its maximum size caused by blocking operations, it does not execute any tasks even despite the fact that blocking operations have already finished and threads are idle.

The culprit seems to be monix.execution.internal.forkJoin.DynamicWorkerThreadFactory - the code above works fine if the Scheduler is defined like this:

implicit val scheduler: Scheduler = 
  Scheduler(new ForkJoinPool(4, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true, 0, 8, 1, null, 60, TimeUnit.SECONDS))

Environment: Monix 3.4.1, Scala 2.13.8, JDK 11

@ghik
Copy link
Contributor Author

ghik commented Jun 15, 2022

OK, now I understand why this was done the way it was - ForkJoinPool changed between JDK8 and JDK11 (it didn't have maxThreads parameter in JDK8). Unfortunately, JDK8 is also prone to this bug so I'm not sure what would a JDK-independent fix look like.

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

Successfully merging a pull request may close this issue.

1 participant