Open Jadarma opened 7 months ago
yes, this is clearly a limitation in the current design. It needs to be followed-up for next milestone, as it's an important change
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Bad stale bot, bad!
Describe the bug Module code generation forces instantiating the module class twice and breaks context isolation. When using annotations, it is impossible to run Koin in parallel, such as in the case of unit / integration tests, as the same one global module will be shared across Koin instances.
To Reproduce Consider the following module:
Which I then install in a Ktor Application:
If I run two Ktor test applications in parallel, I get the following logged:
So, two different Ktor instances, with two different Koin instances, with two different module instances, ended up generating the same seed... hmm.
Looking at the generated code, I see:
Even though the module is an extension over an already created instance of
MyModule
, it resolves to a global variable which instantiates it itself once more, and that instance is then used to provide the values, regardless of module or Koin instance they were defined in.Expected behavior The
.module
extension should get a module based on the instance it was called on instead of global state.Koin project used and used version:
io.insert-koin:koin-bom:3.5.1
io.insert-koin:koin-annotations-bom:1.3.0
Extra notes: This is a more trivial example for reproducibility, how I originally found this bug is that I was trying to execute parallel integration tests with different databases, but I got constraint violation exceptions, which made no sense unless the same connection was reused. I was able to trace back the culprit to this. If I instead declare the module with the normal DSL, then the issue goes away.