-
Notifications
You must be signed in to change notification settings - Fork 517
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
Fix thread safety when resolving at the same time on different threads. #574
base: master
Are you sure you want to change the base?
Conversation
Hi guys! @Sali0m, would you believe that is missing just the lint and spm-check to be able to merge this Pull Request? I'm asking it because my application is needing this fix too. I'd be happy to help merging this PR. |
I have no idea why the checks haven't run tbh, if you have any idea how I can make them run, please do tell :) |
I need an approval from a maintainer for the actions to run |
Oh I see. Let's try adding them to this thread: @yoichitgy, @jakubvano, @1ucas and @maxim-chipeev you guys are the top 4 commiters here. Any chance any of you are also a maintainer to take a look in this PR? We need a maintainer approval so the actions run to validate this pull request. |
Hi, thank you for contributing and for pinging me! Could you share a bit more on the nature of the problem? ThreadSafeDictionary is not performant enough for the needs of very-large codebases. Is there a chance you can reproduce the issue with tests? |
I'll try to find some time to make a reproduction project so you can better understand the issue, but since it's been a few months, it may take a while for me to remember how to reproduce it. What I can remember is that we were resolving a few things on different thread while there may have been a register too, and one of the dictionary then crashed. |
Hello @maxim-chipeev.
|
Hi Nathan, thank you for sharing this snippet—from what I can see that does look unsafe. The Container returned by What I can do alternatively to this PR, is remove the "synchronization" logic that seems to be confusing—and make Containers inherently threadsafe to access. Can you try if it crashes with the following being the only synchronize call?
|
Hello @maxim-chipeev.
But the solution above crashes the app. The only way to completely solve this issue by using the
But as i commented in the code snippet i sent previously i believe the performance of this approach would be even worse than using the ThreadSafeDictionary since the whole register and resolve block would be executed by the |
Why not the following?
What I'm seeing is a concurrent registration on a non-threadsafe Container. That should be expected to crash. |
I see, what I'm looking to know then is whether registration is something you commonly see in your codebase long after app-launch? In our cases all of our registrations happen at the beginning of the app lifecycle. |
In my use case since i have different modules we only register the essential and the most used features in the beginning of the app life cycle. This could also be the case for apps which have features enabled by feature flags or paid features by user. And using the synchronized container only for the "lazy registration" where the registrations are done at a later moment isn't something recommended at least according to the function documentation since this could cause different different graph scope. |
Hello, as mentioned in this issue: #547
We encountered on our project some crashes when we try to resolve some dependencies on different threads.
Here is what the stack trace of the different threads looks like (second one is the one crashing in this case).
Using the previously used ThreadSafeDictionary seem to fix the issue.