Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix deadlock in mysql poolmanager attempt #2 #61

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

Closed

Conversation

@brokuene
Copy link

@brokuene brokuene commented Mar 5, 2024

Adding PR again as my previous PR #60 was not processed due to OCA - which is now sorted out.

There is deadlock bug in MySqlPoolManager.cs. It makes the library unusable in any .Net applications with SynchronizationCotnext while using pooling feature.

It causes a deadlock of threads, application will hang forever. Affected are:

  • ASP .NET MVC app (on full .net framework),
  • Windows Forms App,
  • WPF app.
    If using Pooling=true in connection string (common scenario).

What is more, it leads to breaking the whole appPool on IIS (for ASP .NET MVC app) as all threads from thread pool will eventually deadlock.

This looks like obvious human error, there is missing ConfigureAwait(false) when awaiting on semaphore. Note that the ConfigureAwait(false) is widely used in all other places at this class but in this one is simply missing.

await waitHandle.WaitAsync(CancellationToken.None);

In this PR:

  • Two places in MySqlPoolManager.cs are fixed to not cause deadlock
  • Changelog and library version updated (I hope this critical bugfix will reach all users sooner than later)
  • Unit test which allows to reproduce the issue (for the sake of simplicity I included only one of the SynchronizationContext scenario to demonstrate deadlock).

How bug was introduced

  1. On 11 Jan 2023 there was change from using lock to SemaphoreSlim in MySqlPoolManager.GetPoolAsync. Unfortunatelly this introduced a bug - the new Semaphore was created every time method is invoked so there was no threadsaffenes at all.
  2. The bug from 1. was fixed by setting the semaphore static so the thread safeness was introduced again. Unfortunately acquiring the lock on semaphore is done asynchronously without using ConfigureAwait(false) so it causes deadlocks in described in this PR scenarios.

siickstar reacted with hooray emoji
...eAwait(false). That affects all apps with SynchronizationContext for example: ASP.NET MVC fullframework app, Windows Forms app, WPF app.
Copy link
Author

brokuene commented Mar 5, 2024

"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."

Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=114272 for updates.
Thanks

Copy link

I Fucking Love you, thanks from the bottom of my heart, you saved my job and my sanity

brokuene reacted with heart emoji

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /