-
Notifications
You must be signed in to change notification settings - Fork 216
Update value under concurrency fails when a cancellation token is registered. #184
Comments
@troydai thanks - can you add a bit more info to this bug? |
Yes. I'm adding except stack to the description. I did talk with @Tratcher and @sebastienros before I file the issue. He's has a rough idea what probably break this scneario. |
Since this ticket is marked for 1.0.0, I guess it was not fixed for RC2?
|
Correct. You managed to reproduce it in the wild? We only managed in contrived background threading scenarios. |
Yep. Adding some "DB initialization" code at the end of var factory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
using (var scope = factory.CreateScope()) {
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
context.Database.EnsureCreated();
if (!context.Users.Any()) {
// Skipped.
}
context.SaveChanges();
} For reasons I can't explain (yet), this alternative pattern causes fewer exceptions: var options = app.ApplicationServices.GetRequiredService<DbContextOptions<ApplicationDbContext>>();
using (var context = new ApplicationDbContext(options)) {
context.Database.EnsureCreated();
if (!context.Users.Any()) {
// Skipped.
}
context.SaveChanges();
} |
Luckily, it seems to only impact the very first request, so it's probably not critical (just a bit annoying 😄) |
@Tratcher curious: can you reproduce it or is it just me? 😄 |
We were able to reproduce, we added some unit tests along with the fix if you want some ways to repro. |
Yep, but it would imply migrating to the nightly builds and this is something I'd really like to avoid for a public sample. |
I face it a lot, every first request after I start the application. |
@gdoron yes it can happen in production. |
Scenario:
InvalidOperationException
is thrown.Issue repo:
https://github.com/troydai/CachingIssues/blob/2a85107b9b572c47d66d2a0303deafecaeaa3166/TestActions/ConcurrencyIssue184.cs#L17
Run the sample follow exception will be thrown from child thread after the value is updated by main thread.
The text was updated successfully, but these errors were encountered: