Hi, I‘m currently migrating a project from IO to f...
# arrow
j
Hi, I‘m currently migrating a project from IO to fx coroutines. It looks like everything works fine, but using
evalOn
(with any pool) seems to cause a deadlock in the IntelliJ debugger. This happens with both the whole application in debug mode and a single function in a test. Is there a wrapper or entry point I missed in the docs?
s
Is there any repdocible snippet you could share?
j
Yes, the simplest case would be
Copy code
suspend fun readImage(path: String): Either<Throwable, ByteArray> = evalOn(IOPool) {
    Either.catch {
        Files.readAllBytes(Path.of(path))
    }
}
with a test (using kotest) like
Copy code
class ReadImageTest : StringSpec() {
    init {
        "should read an existing image file" {
            readImage("logos/logo.png") shouldBeRight { bytes ->
                bytes.size shouldBeGreaterThan 1000
            }
        }

        "should return an error for a non-existing file" {
            readImage("logos/foo.png").shouldBeLeft()
        }
    }
}
Looks like two stack frames have each other as
callerFrame
in
Copy code
private tailrec fun CoroutineStackFrame.owner(): CoroutineOwner<*>? =
        if (this is CoroutineOwner<*>) this else callerFrame?.owner()
s
Copy code
private tailrec fun CoroutineStackFrame.owner(): CoroutineOwner<*>? =
        if (this is CoroutineOwner<*>) this else callerFrame?.owner()
Where did you find following snippet? It's not from within Arrow Fx Coroutines?
I could not reproduce this issue locally. The above snippet runs fine for me with Arrow Fx Coroutines
0.11.0
and Kotest
4.2.6
. I only changed
Path.of
to
Paths.get
since
Path.of
wasn't compiling for me with
kotlin-std:1.4.10
. My gradle looked like the following:
Copy code
implementation "org.jetbrains.kotlin:kotlin-stdlib"
implementation "io.arrow-kt:arrow-fx-coroutines:0.11.0"
testImplementation 'io.kotest:kotest-runner-junit5:4.2.6'
testImplementation 'io.kotest:kotest-assertions-core:4.2.6'
testImplementation 'io.kotest:kotest-property:4.2.6'
testImplementation 'io.kotest:kotest-assertions-arrow:4.2.6'
I'm not sure how you were testing the files, since you didn't include that part in your snippet. So I saw the first test fail, with
Left(java.nio.file.NoSuchFileException: logos/logo.png) is of type arrow.core.Either.Left but expected arrow.core.Either.Right
. The second test passed as expected since
foo.png
is also not found.
j
Thank you for looking into this 🙂 I created a minimal project to try to reproduce this (https://github.com/jenssuhr/fx-coroutines-evalon) and from the results it looks like it might be a problem with either kotest or my test setup: • Running main and tests works fine • Debugging the test results in a deadlock • Debugging main works fine
s
So this is only a problem when debugging? Strange... I know Kotlin Std Coroutines does some special things for debugging coroutines, but Arrow Fx Coroutines implements the
CoroutineStackFrame
contract in the exact same way as KotlinX Coroutines, and as described by the Kotlin Std. I am not 100% sure what goes in when you debug, I think there is even some special support in IDEA for debugging coroutines. The snippet you shared earlier relating to
CoroutineStackFrame
doesn't come from Arrow Fx Coroutines, and it looks like it might result in an eternal loop. Could that be the culprit?
j
Yes, the problem only occurs while trying to debug. The program runs just fine without a debugger attached. I’ll have a look at the source of the snippet with the
CouroutineStackFrame
That snippet is from https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/src/debug/internal/DebugProbesImpl.kt > I think there is even some special support in IDEA for debugging coroutines. With these two hints, I tried setting the following option:
👍 1
and now it works just fine
Thank you again 🙂
s
Thank you for keeping me posted! Interesting to know!
🙌 1
k
That’s interesting. Good to know indeed.
s
Throwback... It seems this was a bug, and it showed up when I was building debug support. When this PR is merged, you should be able to turn on Coroutine debugging again 🙂 https://github.com/arrow-kt/arrow-fx/pull/308/files?file-filters%5B%5D=.gradle&amp;file-filters%5B%5D=.kt#diff-1be014d56e7112872d4d59ca03c7a1288b970b2ee81ed09b2c7daa9eae21c4aeR92
🦜 2
j
Awesome, thanks! 🙂