-
Notifications
You must be signed in to change notification settings - Fork 12
Fix a race condition in ReconfigureTenant #38
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
Conversation
…configureTenant to set the new tenant scope instance.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #38 +/- ##
===========================================
+ Coverage 90.62% 93.57% +2.95%
===========================================
Files 5 5
Lines 96 109 +13
Branches 27 28 +1
===========================================
+ Hits 87 102 +15
+ Misses 4 3 -1
+ Partials 5 4 -1 ☔ View full report in Codecov by Sentry. |
|
While I see what this is trying to do, part of the challenge here is that there's an assumption that configuring Autofac is thread-safe. Component registration and container building have never been thread-safe. There's going to be the same race condition if someone is calling We used to have reader/writer locking (#8) but that got removed because it didn't work with Anyway, that's what I'm thinking about. I wonder if this would be a good use of |
…un in parallel if needed (in the previous solution, calls to GetTenantScope could return an empty scope until the call the ReconfigureTenant is completed)
|
I completely agree. The first solution aimed at minimize the amount of changes while making ReconfigureTenant deterministic. |
tillig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking nice, I like the updated use of the ConcurrentDictionary bits. I have a couple of inline comments, but minor stuff. Thanks!
… ReconfigureTenant implementation
|
I have also added a test for the case where we go through the Add path in the AddOrUpdate. |
tillig
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Let me get this merged in and I'll make a 0.0.1 release with it.
ReconfigureTenant removes the tenant scope before adding the reconfigured one. If another thread calls GetTenantScope between the remove and the add, an empty scope is kept in the _tenantLifetimeScopes dictionary.