https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Albert

09/17/2018, 1:44 PM
I have a strange issue, but I am not sure if it is related to coroutines. But I have the following unit test:
Copy code
@Test fun testActor() {
  val testActor = actor<String> {
    println(channel.receive())
  }

  testActor.sendBlocking("CHANNEL-MESSAGE")
}
When I run this locally on my machine I see
CHANNEL-MESSAGE
being printed. But when I build this with docker it is never received. My
Dockerfile
looks like:
Copy code
FROM maven:3.3.9-jdk-8
COPY . project/
WORKDIR project
RUN mvn clean package
I used version
3.3.9
which is the same on my local machine. With docker it actually freezes on the
sendBlocking
. Anyone a clue how this is possible?
g

gildor

09/17/2018, 11:24 PM
You use blocking operation. Maybe you blocked all the threads for some reason? Is it reproducible with such simple example?
Maybe you could provide some self contained example
a

Albert

09/18/2018, 9:17 AM
Making a self contained example is difficult with this one. Because of docker and the configuration. The thing what "helped" was increasing the amount of cores in the container from 2 (default) to 3 (on Windows).
g

gildor

09/18/2018, 9:20 AM
I think you blocked all the threads of common pool and no more threads to dispatch coroutines
a

Albert

09/18/2018, 9:32 AM
But then it is still unclear to me why it is happening in docker only. when I do this on my host exactly the same way it works
g

gildor

09/18/2018, 9:34 AM
Because on your host you just have more available threads in CommonPool. CommonPool is
cpuNum - 1
But, I do not exclude that there is still some bug, this is why I asked self contained example
No need to set amount of cores for docker, you can instead set system property
kotlinx.coroutines.default.parallelism
to set minimal amount of threads in commonpool
👍 1
also you can try to use new experimantal dispatchers, that can handle such cases automatically and start additional threads if all of existing are blocked
actually with 2 cores you have only 1 thread in CommonPool
4 Views