-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated modules use global state and break context isolation. #102
Labels
Milestone
Comments
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! |
Fixed in #136 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: