Hello :wave::skin-tone-4: I’ve gotta a question h...
# coroutines
h
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
sounds like a different classloader
since ktor supports auto-reload I wouldn't be surprised if that were the cause
h
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
some of the setup might be automatic in development mode, I'm not sure. #ktor might know
h
I should probably put this question over that channel as well, right? 🤷🏽‍♂️ Thanks anyway for trying to help
l
Looks like a ktor rather than a coroutines issue to me, so makes more sense in #ktor I think.
h
Fair enough. I’ve already dropped the message there. I will probably update here once I figure.
a
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
Not sure if that would work. However, I think I’ve just figured what could be wrong. https://youtrack.jetbrains.com/issue/KTOR-2306