-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Use strings as identifiers in the in-memory database rather than model references #30364
Comments
Not sure this is the same, but I just what looks like a flaky in-memory test failure in CI:
|
Insert_update_and_delete_with_wrapped_Uri_key
|
So I figured out what is going on here. Essentially, the in-memory tests are filling the This only happens when For now, I will push two PRs: one with the debugging in the model cache so others can look, and one that increases the cache size to unblock the C.I. This is likely not a good long-term solution--we should likely change the in-memory database implementation instead. It's interesting that it looks like the way |
Well done tracking this down... makes sense! If you're able to repro this relatively easily, then we can bisect to see when it started and possibly track down the cause for the change. In an ideal world, maybe it this could be managed via EnsureCreated/EnsureDeleted like for normal databases, where the test explicitly drops the database when it's done; that would prevent relying on automatic LRU/purging logic which is unpredictable... |
(I wonder if this started triggering simply because we happened to add a ton more new tests at some point?) |
The in-memory database doesn't go away; that's what was hard to debug about this. However, the database uses reference equality on model types to key tables. So if the model changes, the items are not found in the database even though the database exists and still contains the data. I think this is the bit we should change to be more like a normal database; the keys for the tables should be derived from the model types, but not ever be the model types themselves. We already have this with the "_useNameMatching", but the key probably needs to be stronger than just the type name if we are to make it the default.
I have a hunch what the cause was which I will investigate. :-) I think we also need to talk about using a single MemoryCache for queries and models, and whether we should allow explicit removal of models from the cache when the application says they are no longer used. |
Additional info:
So it seems like an application that creates a lot of models (which should be uncommon, but we know some people do this for multi-tenancy) will quickly fill its cache with models and start evicting queries. |
This is the root cause: #30365 |
We also need to (lazily) invalidate the cached queries if the corresponding model is no longer cached. |
Notes from design meeting:
|
This test failed on one run on my machine. Probably a test concurrency issue; could be a concurrency issue inside EF/the in-memory provider.
The text was updated successfully, but these errors were encountered: