Hello, I was wondering if someone from Ktor is loo...
# ktor
t
Hello, I was wondering if someone from Ktor is looking into the following issue. I would really like a solution for this. If anyone has any suggestions how I could fix this, please let me know. https://github.com/ktorio/ktor/issues/1263
2
Hey @e5l, you self assigned this issue. Is there anything I can do to help?
e
Nope, we’re already working on improving stack traces quality.
👍 1
t
Hi again @e5l, good to hear you are working on it. Is this already included in 1.2.4? I updated Ktor to 1.2.4 and my app. The stack traces are still the same. Lots of users are getting this crash and I really want to fix this.
e
Nope, but changes are in
master
t
@e5l wow that's great! Could you link to the commit so I can try it out?
If so, is it ready to use or is it still a work in progress?
e
It’s ready, but there are few things to do for exceptions with custom state. Still WIP
t
Ok so what would happen for those exceptions? Should it be safe to try out in my app?
e
They don’t recover the stack. It’s safe to try it out 🙂. I would be happy to hear the feedback.
t
Ok great, I will try it out and give feedback. I really appreciate your help!
🙏 1
Hi @e5l, I cherry picked that commit onto the 1.2.x branch and built with mavenLocal. I made sure that this version was included in my app. I got the same crash again on Firebase, but unfortunately the stack trace does not show more information. None of the affected users (375+ users in last 7 days) so far, have reported how they got the crash. I have no idea how they get the crash. Here is the new stack trace (with coroutines debug mode enabled as well): https://gist.github.com/Thomas-Vos/75a037a2e0de62380f4b31bbf211c8d8 Is there anything I can do to help?
@e5l Does a
java.net.SocketTimeoutException
fall under a "custom state" exception?
e
Nope. Are you installing
DebugProbes
before executing the request?
t
@e5l No, I only have the following:
Copy code
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
Do I need to add
DebugProbes
as well? Would that work for an Android app?
e
Yep, there is no way to make it without debug probes
t
@e5l Ok, but the documentation says that it is not compatible with Android. Is that no longer true? https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-debug/README.md#debug-agent-and-android
e
@Vsevolod Tolstopyatov [JB]
v
Unfortunately, it’s still not compatible with Android
t
That’s disappointing. Any ideas how I could get a real stack trace so I can solve this issue?
I really need a fix for this crash as it is affecting a lot of users in my app.
I am not able to reproduce this exception myself in my app. A stack trace would really make this a lot easier. @e5l do you have any ideas?
There are some other people who responded to the GitHub issue with the same issue (https://github.com/ktorio/ktor/issues/1263)
Hello @Dominaezzz, @Santosh Astagi, @spierce7. On GitHub you responded with a similar issue. Do any of you have more details which could help solve this issue?
d
I think it's just a stack frame building issue.
t
@Dominaezzz thanks for your response. I don’t exactly get what you are trying to say, but without a stack trace I just cannot find the cause in my app.
Here is a small example:
Copy code
GlobalScope.launch {
    val deferred = async {
        val client = HttpClient(OkHttp) {
            engine {
                config {
                    // Make sure there is a timeout
                    readTimeout(1, TimeUnit.MILLISECONDS)
                }
            }
        }
        client.get<String>("<https://google.com>")
    }
    deferred.await()
}
This throws the following exception: https://gist.github.com/Thomas-Vos/adca67cc732d87691662725e56fc59b3 As you can see it does not show a stack trace referencing my code. @e5l How am I supposed to find the cause in my app? I have Kotlin debug mode enabled, but without the DebugPropes as that is not compatible with Android.
d
Suspend functions "break" the stack frame. Since the JVM doesn't know what coroutines are. So kotlin tries to fake a stack frame that looks like what we expect.
t
Yes, that explains why the stack trace is missing. Would something like this make sense? At least temporarily until one of the users gets this exception again? This way at least I know where in my code I called this suspend function, right?
Copy code
try {
    deferred.await()
} catch (throwable: Throwable) {
    throw RuntimeException(throwable)
}
d
Yes, that could work for now.
s
Sorry just seeing this, reading through, @Thomas did that help you uncover the issue?
t
@Santosh Astagi no, unfortunately it didn't. I am still unable to find the cause of the exception. Currently my worst crash in Firebase.
I would really like to solve it but just do not know how
One user reported that my app did not crash with WiFi off (so no timeout exception but probably an immediate socket exception). Apperantly that did not crash, but I do catch both types of exceptions so not sure why.
s
hmmm, we are also stumped, we are unable to reproduce it, but see this crash in our logs
Did you update to 1.2.5?
t
@Santosh Astagi I'm still on version 1.2.4.
s
1.2.5 seemed to have some promising updates
check release log
Planning to use 1.2.5 and check the crash logs
t
I'll look into it tomorrow, thanks.
Just updated to Ktor 1.2.5 and got a reported crash with a different stack trace. I think it is the same issue. Does this give someone any ideas what could be going wrong?
s
This is a little promising atleast
So, I have been digging around a bit
and I found this bug, could this be related to ktor:
kotlin native may have an issue with some segment pooling of threads. Look at the last comment @Thomas
t
@Santosh Astagi How exactly is that related? It is a different exception and those GitHub comments are about Kotlin Native. I am using Kotlin JVM on Android
Have you updated your app with Ktor 1.2.5? I am curios what your stack trace will be. It looks like the cause for my stack trace is happening inside an AsyncTask. I am not using them myself, The only place I can think of they are used by the system in my app are in the Android Widgets / JobIntentService. They probably use an AsyncTask in the background. But that is just a guess.
s
I am releasing next week, will update here
the reason I brought that up, is ktor is native, it's underlying engine may not be
t
ktor is native, it’s underlying engine may not be
As far as I know that is not possible. Kotlin/Native means that it compiles to C for e.g. iOS. I am using Kotlin JVM (so no Kotlin/Native at all). Could you explain in more detail?
s
While the networking is happening completely at at the platform level, there are other things that are in native i.e. other features that you install in ktor that run in the JVM but it is implemented in the common layer, just wondering if this may be connected.
t
Code in the mpp common layer still compiles to Kotlin JVM
s
@Thomas we released last week with the upgraded versiona nd we are not seeing that appear as a crash, but instead is listed as a non-fatal. Just though I'd let you know.
t
@Santosh Astagi do you mean non fatal in Firebase? That means you are catching the exception and logging it to Firebase manually.
s
yes
We started catching SerializationExceptions, that is the only new exception, we started catching
That was a false alarm, we are seeing it again, now, but it showed up more than a week after releasing.
This has stopped happening for us now.