From 2d7714d6be8743318233c408a082b5a1d1be2799 Mon Sep 17 00:00:00 2001 From: brokuene Date: Mon, 18 Dec 2023 10:28:36 +0100 Subject: [PATCH 1/2] Fix deadlock in MySqlPoolManager.GetPoolAsync due to missing ConfigureAwait(false). That affects all apps with SynchronizationContext for example: ASP.NET MVC fullframework app, Windows Forms app, WPF app. --- MySQL.Data/src/MySqlPoolManager.cs | 4 +- .../tests/MySql.Data.Tests/ConnectionTests.cs | 53 ++++++++++++++++++- .../MySql.Data.Tests/MySql.Data.Tests.csproj | 1 + 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/MySQL.Data/src/MySqlPoolManager.cs b/MySQL.Data/src/MySqlPoolManager.cs index 7ee452d25..a8de545fc 100644 --- a/MySQL.Data/src/MySqlPoolManager.cs +++ b/MySQL.Data/src/MySqlPoolManager.cs @@ -139,7 +139,7 @@ public static async Task GetPoolAsync(MySqlConnectionStringBuilder se { string text = GetKey(settings); - await waitHandle.WaitAsync(CancellationToken.None); + await waitHandle.WaitAsync(CancellationToken.None).ConfigureAwait(false); MySqlPool pool; Pools.TryGetValue(text, out pool); @@ -209,7 +209,7 @@ private static async Task ClearPoolByTextAsync(string key, bool execAsync) public static async Task ClearAllPoolsAsync(bool execAsync) { - await waitHandle.WaitAsync(); + await waitHandle.WaitAsync().ConfigureAwait(false); // Create separate keys list. List keys = new List(Pools.Count); diff --git a/MySQL.Data/tests/MySql.Data.Tests/ConnectionTests.cs b/MySQL.Data/tests/MySql.Data.Tests/ConnectionTests.cs index 5aaf85f4a..619f35296 100644 --- a/MySQL.Data/tests/MySql.Data.Tests/ConnectionTests.cs +++ b/MySQL.Data/tests/MySql.Data.Tests/ConnectionTests.cs @@ -1497,9 +1497,58 @@ public void OpenMultipleConnectionsOnMultipleThreads() Task.WaitAll(tasks.ToArray()); } - #region Methods +#if NET462 || NET48 + /// + /// Deadlock bug on application with Synchronization context (Net full framework Asp.NET app, Windows Forms App, WPF app. + /// Any App with - WindowsFormsSynchronizationContext, DispatcherSynchronizationContext and AspNetSynchronizationContext + /// will deadlock if missing ConfigureAwait(false) inside the MySql library. + /// + [Test] + public void OpenMultipleConnectionsOnMultipleThreadsInAppWithSynchronizationContext() + { + var sb = new MySqlConnectionStringBuilder(Connection.ConnectionString); + sb.Pooling = true; + + var tasks = new List(); + for (int i = 0; i < 5; i++) + { + tasks.Add(Task.Run(() => + { + SynchronizationContext.SetSynchronizationContext(new System.Windows.Forms.WindowsFormsSynchronizationContext()); + using (var connection = new MySqlConnection(sb.ConnectionString)) + { + connection.Open(); + } + })); + } + Assert.IsTrue(Task.WaitAll(tasks.ToArray(),5000),"Deadlock when connecting - cancelled waiting after 5 seconds."); + } + + [Test] + public void OpenAsyncMultipleConnectionsOnMultipleThreadsInAppWithSynchronizationContext() + { + var sb = new MySqlConnectionStringBuilder(Connection.ConnectionString); + sb.Pooling = true; + + var tasks = new List(); + for (int i = 0; i < 5; i++) + { + tasks.Add(Task.Run(() => + { + SynchronizationContext.SetSynchronizationContext(new System.Windows.Forms.WindowsFormsSynchronizationContext()); + using (var connection = new MySqlConnection(sb.ConnectionString)) + { + connection.OpenAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + } + })); + } + Assert.IsTrue(Task.WaitAll(tasks.ToArray(),5000),"Deadlock when connecting - cancelled waiting after 5 seconds."); + } +#endif + + #region Methods - private void ExecuteQueriesSuccess(string sql, string password) + private void ExecuteQueriesSuccess(string sql, string password) { if (Version < new Version(8, 0, 17)) return; var sb = new MySqlConnectionStringBuilder(Connection.ConnectionString); diff --git a/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj b/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj index 2b21049c2..bf712d174 100644 --- a/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj +++ b/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj @@ -42,6 +42,7 @@ + From 7147c0950fadb5076c605ace302560895495e5b6 Mon Sep 17 00:00:00 2001 From: brokuene Date: Mon, 18 Dec 2023 10:15:28 +0100 Subject: [PATCH 2/2] Update version 8.2.0 -> 8.2.1 --- CHANGES | 4 ++++ .../templates/custom/partials/class.header.tmpl.partial | 2 +- EFCore/Directory.Build.targets | 6 +++--- EntityFramework/src/MySql.Data.EntityFramework.csproj | 2 +- .../MySql.EntityFramework.Basic.Tests.csproj | 2 +- .../MySql.EntityFramework.CodeFirst.Tests.csproj | 2 +- .../MySql.EntityFramework.Migrations.Tests.csproj | 2 +- .../src/MySQL.Data.OpenTelemetry.csproj | 2 +- MySQL.Data/src/MySql.Data.csproj | 2 +- MySQL.Data/src/Properties/VersionInfo.cs | 4 ++-- MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj | 2 +- MySQL.Data/tests/MySqlX.Data.Tests/MySqlX.Data.Tests.csproj | 2 +- MySql.Web/src/MySql.Web.csproj | 2 +- MySql.Web/tests/MySql.Web.Tests.csproj | 2 +- 14 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index cf700e975..22872bb69 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +8.2.1 +- Fixed deadlock bug in MySqlPoolManager.GetPoolAsync affecting apps with SynchronizationContext like ASP.NET MVC full framework app, Windows Forms app, WPF app. + + 8.2.0 - Migrated installer to Wix 4.0 (WL15847). - Fixed bug Opening two MySqlConnections simultaneously can crash (Oracle Bug #35307501). diff --git a/Documentation/templates/custom/partials/class.header.tmpl.partial b/Documentation/templates/custom/partials/class.header.tmpl.partial index 9a663a1e5..6c74c5dac 100644 --- a/Documentation/templates/custom/partials/class.header.tmpl.partial +++ b/Documentation/templates/custom/partials/class.header.tmpl.partial @@ -25,7 +25,7 @@ {{/implements.0}}
{{__global.namespace}}: {{{namespace.specName.0.value}}}
{{__global.assembly}}: {{assemblies.0}}.dll
-
Version: 8.2.0
+
Version: 8.2.1
{{__global.syntax}}
{{syntax.content.0.value}}
diff --git a/EFCore/Directory.Build.targets b/EFCore/Directory.Build.targets index 08bf7e756..6c390c7ba 100644 --- a/EFCore/Directory.Build.targets +++ b/EFCore/Directory.Build.targets @@ -1,16 +1,16 @@ Copyright (c) 2021, 2023, Oracle and/or its affiliates. - 6.0.21+MySQL8.2.0 + 6.0.21+MySQL8.2.1 Copyright (c) 2022, 2023, Oracle and/or its affiliates. - 7.0.10+MySQL8.2.0 + 7.0.10+MySQL8.2.1 Copyright (c) 2023, Oracle and/or its affiliates. - 8.0.0-preview+MySQL8.2.0 + 8.0.0-preview+MySQL8.2.1 \ No newline at end of file diff --git a/EntityFramework/src/MySql.Data.EntityFramework.csproj b/EntityFramework/src/MySql.Data.EntityFramework.csproj index 3ad54520c..9f33667b2 100644 --- a/EntityFramework/src/MySql.Data.EntityFramework.csproj +++ b/EntityFramework/src/MySql.Data.EntityFramework.csproj @@ -4,7 +4,7 @@ MySql.Data.EntityFramework Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net462;netstandard2.1; $(NoWarn);CS1591 diff --git a/EntityFramework/tests/MySql.EntityFramework.Basic.Tests/MySql.EntityFramework.Basic.Tests.csproj b/EntityFramework/tests/MySql.EntityFramework.Basic.Tests/MySql.EntityFramework.Basic.Tests.csproj index fa40e0500..51ff85907 100644 --- a/EntityFramework/tests/MySql.EntityFramework.Basic.Tests/MySql.EntityFramework.Basic.Tests.csproj +++ b/EntityFramework/tests/MySql.EntityFramework.Basic.Tests/MySql.EntityFramework.Basic.Tests.csproj @@ -4,7 +4,7 @@ MySql.Data.EntityFramework.CodeFirTests Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net7.0 MySql.EntityFramework.Basic.Tests diff --git a/EntityFramework/tests/MySql.EntityFramework.CodeFirst.Tests/MySql.EntityFramework.CodeFirst.Tests.csproj b/EntityFramework/tests/MySql.EntityFramework.CodeFirst.Tests/MySql.EntityFramework.CodeFirst.Tests.csproj index 394433997..70d3832be 100644 --- a/EntityFramework/tests/MySql.EntityFramework.CodeFirst.Tests/MySql.EntityFramework.CodeFirst.Tests.csproj +++ b/EntityFramework/tests/MySql.EntityFramework.CodeFirst.Tests/MySql.EntityFramework.CodeFirst.Tests.csproj @@ -4,7 +4,7 @@ MySql.Data.EntityFramework.CodeFirst.Tests Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net7.0 MySql.EntityFramework.CodeFirst.Tests diff --git a/EntityFramework/tests/MySql.EntityFramework.Migrations.Tests/MySql.EntityFramework.Migrations.Tests.csproj b/EntityFramework/tests/MySql.EntityFramework.Migrations.Tests/MySql.EntityFramework.Migrations.Tests.csproj index 8be578e10..fab58a77b 100644 --- a/EntityFramework/tests/MySql.EntityFramework.Migrations.Tests/MySql.EntityFramework.Migrations.Tests.csproj +++ b/EntityFramework/tests/MySql.EntityFramework.Migrations.Tests/MySql.EntityFramework.Migrations.Tests.csproj @@ -4,7 +4,7 @@ MySql.Data.EntityFramework.Migrations.Tests Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net7.0 MySql.EntityFramework.Migrations.Tests diff --git a/MySQL.Data.OpenTelemetry/src/MySQL.Data.OpenTelemetry.csproj b/MySQL.Data.OpenTelemetry/src/MySQL.Data.OpenTelemetry.csproj index 1d144fae4..3dcc39f8a 100644 --- a/MySQL.Data.OpenTelemetry/src/MySQL.Data.OpenTelemetry.csproj +++ b/MySQL.Data.OpenTelemetry/src/MySQL.Data.OpenTelemetry.csproj @@ -4,7 +4,7 @@ MySql.Data.OpenTelemetry Copyright (c) 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle netstandard2.0 MySql.Data.OpenTelemetry diff --git a/MySQL.Data/src/MySql.Data.csproj b/MySQL.Data/src/MySql.Data.csproj index 26d1d1652..1070cd1fa 100644 --- a/MySQL.Data/src/MySql.Data.csproj +++ b/MySQL.Data/src/MySql.Data.csproj @@ -5,7 +5,7 @@ MySql.Data.MySqlClient .Net Core Class Library Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle MySql.Data net462;net48;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0; diff --git a/MySQL.Data/src/Properties/VersionInfo.cs b/MySQL.Data/src/Properties/VersionInfo.cs index 05a18cd26..2c893fae9 100644 --- a/MySQL.Data/src/Properties/VersionInfo.cs +++ b/MySQL.Data/src/Properties/VersionInfo.cs @@ -40,6 +40,6 @@ // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("8.2.0")] -[assembly: AssemblyInformationalVersion("8.2.0")] +[assembly: AssemblyVersion("8.2.1")] +[assembly: AssemblyInformationalVersion("8.2.1")] [assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj b/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj index bf712d174..fa075fc22 100644 --- a/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj +++ b/MySQL.Data/tests/MySql.Data.Tests/MySql.Data.Tests.csproj @@ -4,7 +4,7 @@ MySql.Data.Tests MySql.Data.Tests Class Library Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. - 8.2.0 + 8.2.1 Oracle Oracle MySql.Data.Tests diff --git a/MySQL.Data/tests/MySqlX.Data.Tests/MySqlX.Data.Tests.csproj b/MySQL.Data/tests/MySqlX.Data.Tests/MySqlX.Data.Tests.csproj index e4f19faa7..0c351cd3d 100644 --- a/MySQL.Data/tests/MySqlX.Data.Tests/MySqlX.Data.Tests.csproj +++ b/MySQL.Data/tests/MySqlX.Data.Tests/MySqlX.Data.Tests.csproj @@ -4,7 +4,7 @@ MySql.Data.Tests MySql.Data.Tests Class Library Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. - 8.2.0 + 8.2.1 Oracle Oracle MySql.Data.Tests diff --git a/MySql.Web/src/MySql.Web.csproj b/MySql.Web/src/MySql.Web.csproj index 46a3075e6..7974e04fe 100644 --- a/MySql.Web/src/MySql.Web.csproj +++ b/MySql.Web/src/MySql.Web.csproj @@ -4,7 +4,7 @@ MySql.Web Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net462;net48; $(NoWarn);CS1591 diff --git a/MySql.Web/tests/MySql.Web.Tests.csproj b/MySql.Web/tests/MySql.Web.Tests.csproj index 78995b8cb..460b6b051 100644 --- a/MySql.Web/tests/MySql.Web.Tests.csproj +++ b/MySql.Web/tests/MySql.Web.Tests.csproj @@ -4,7 +4,7 @@ MySql.Web.Tests Copyright (c) 2016, 2023, Oracle and/or its affiliates. en-US - 8.2.0 + 8.2.1 Oracle net462;net48; MySql.Web.Tests