Registry Mirror
Skip to content

Conversation

@ajcvickers

Copy link
Copy Markdown
Contributor

Fixes #25797
Fixes #26016

I identified two race conditions, both caused by splitting state across multiple data structures. In particular, the Semaphore and the two ConcurrentStacks must stay in sync--that is, the Semaphore can let someone get a collection if and only if there is a connection available in the one of the stacks.

The fix is to wrap all these things in a single lock. It's possible that we don't need a full lock, but we already have one to protect _collections which can easily be expanded to cover the right areas.

Once this lock is used, the semaphore is no longer needed, and the stacks don't need to be concurrent because they are protected by the lock.

Fixes #25797
Fixes #26016

I identified two race conditions, both caused by splitting state across multiple data structures. In particular, the Semaphore and the two ConcurrentStacks must stay in sync--that is, the Semaphore can let someone get a collection if and only if there is a connection available in the one of the stacks.

The fix is to wrap all these things in a single lock. It's possible that we don't need a full lock, but we already have one to protect _collections which can easily be expanded to cover the right areas.

Once this lock is used, the semaphore is no longer needed, and the stacks don't need to be concurrent because they are protected by the lock.
@ajcvickers
ajcvickers requested a review from a team December 14, 2023 16:30
while (TryPop(_warmPool, out var connection))
{
DisposeConnection(connection);
DisposeConnection(connection!);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Strange that you had to bang here

@ajcvickers ajcvickers Dec 14, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Some things are not ideal because of the cross-compile to .NET Framework.

@ajcvickers
ajcvickers merged commit 555421e into main Dec 14, 2023
@ajcvickers
ajcvickers deleted the 231214_OneFileOneDbOops branch December 14, 2023 17:48
@sebbarg

sebbarg commented Dec 21, 2024

Copy link
Copy Markdown

Will this fix not be backported to NET v8?

@AndriySvyryd

Copy link
Copy Markdown
Member

@sebbarg No, there weren't enough user reports and the servicing bar for EF 8 is high now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants