Skip to content

Fix race in cache eviction #18528

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix race in cache eviction #18528

wants to merge 2 commits into from

Conversation

majocha
Copy link
Contributor

@majocha majocha commented May 2, 2025

I spotted a bug in the recently merged general purpose cache.

Let's fix it before folks start complaining.

Copy link
Contributor

github-actions bot commented May 2, 2025

❗ Release notes required

@majocha,

Caution

No release notes found for the changed paths (see table below).

Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format.

The following format is recommended for this repository:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request.

You can open this PR in browser to add release notes: open in github.dev

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.300.md No release notes found or release notes format is not correct

Comment on lines +225 to +233
// Store updates are not synchronized. It is possible the entity is no longer in the queue.
| EvictionQueueMessage.Update entity when isNull entity.Node.List -> ()
Copy link
Contributor Author

@majocha majocha May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bugfix. We obviously don't want to lock the ConcurrentDictionary for eviction queue updates.
This makes a race possible where an Update is posted just as the item was being evicted.
In effect Node.List was null, and the mailbox processor silently crashes.
This would happen during intensive cache use with evictions going on, for example when switching branches or solutions in the IDE.

The symptom of this would be excessive allocations. Or lack of eviction if you take a look at the metrics.

This is tested manually in the IDE and confirmed that no longer reproduces.

@majocha majocha marked this pull request as ready for review May 2, 2025 19:34
@majocha majocha requested a review from a team as a code owner May 2, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

1 participant