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

Helio

04/25/2021, 2:55 AM
Hello 👋🏽 I’ve gotta a question here which I’m not entirely sure if it relates with Coroutines or Ktor. Apologies if this is the wrong channel. Well, I’ve recently updated Kotlin
1.4.10 -> 1.4.32
and Ktor
1.4.2 -> 1.5.3
. I was definitely expecting some of Unit tests to break due to compatibility and I’ve already fixed them. However, there are still 4 of them that I’m struggling to understand what could be wrong. When one of the unit tests starts, it adds an entity to a Global Variable with type
mutableListOf<MyModel>()
. I can confirm that the value was added successfully.
ArrayList@XXXX
. However, when one of the routes of my Ktor server attempt to read the value from that Global Variable, it is empty and the id of the object is now
ArrayList@YYYY
. It looks like when
embeddedServer(…).start()
is executed, it creates a new instance of the Global Object, hence it is empty. I’ve already tried many things, SynchronizeListOf, add the global variable into an object, but no matter what I do the reference of the GlobalObject into Ktor is always different. Would anyone be able to shed some light, please? Thanks heaps.
ktor 1
e

ephemient

04/25/2021, 3:06 AM
sounds like a different classloader
since ktor supports auto-reload I wouldn't be surprised if that were the cause
h

Helio

04/25/2021, 3:09 AM
Thanks for your response @ephemient. You mean https://ktor.io/docs/auto-reload.html?
Pretty sure we are not using it in our tests. Nor development to be honest.
e

ephemient

04/25/2021, 3:12 AM
some of the setup might be automatic in development mode, I'm not sure. #ktor might know
h

Helio

04/25/2021, 3:13 AM
I should probably put this question over that channel as well, right? 🤷🏽‍♂️ Thanks anyway for trying to help
l

louiscad

04/25/2021, 3:27 AM
Looks like a ktor rather than a coroutines issue to me, so makes more sense in #ktor I think.
h

Helio

04/25/2021, 4:07 AM
Fair enough. I’ve already dropped the message there. I will probably update here once I figure.
a

Arkadii Ivanov

04/25/2021, 6:48 PM
Maybe you could make the global variable lazy and put a breakpoint in its initializer, in order to find out the place creating the second instance.
h

Helio

04/25/2021, 9:37 PM
Not sure if that would work. However, I think I’ve just figured what could be wrong. https://youtrack.jetbrains.com/issue/KTOR-2306
6 Views