Skip to content

Commit

Permalink
Fix hang when disposing MySqlDataSource twice on .NET Framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Jan 12, 2024
1 parent ebcf3cf commit 2f95bb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MySqlConnector/Core/ConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ public void Dispose()
using var dnsCheckWaitHandle = new ManualResetEvent(false);
m_dnsCheckTimer.Dispose(dnsCheckWaitHandle);
dnsCheckWaitHandle.WaitOne();
m_dnsCheckTimer = null;
}
if (m_reaperTimer is not null)
{
using var reaperWaitHandle = new ManualResetEvent(false);
m_reaperTimer.Dispose(reaperWaitHandle);
reaperWaitHandle.WaitOne();
m_reaperTimer = null;
}
#endif
}
Expand Down
11 changes: 11 additions & 0 deletions tests/IntegrationTests/MySqlDataSourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public void OpenConnection()
Assert.Equal(ConnectionState.Open, connection.State);
}

[Fact]
public void DoubleDispose()
{
using var dbSource = new MySqlDataSource(AppConfig.ConnectionString);
using (var connection = dbSource.OpenConnection())
{
Assert.Equal(ConnectionState.Open, connection.State);
}
dbSource.Dispose();
}

[Fact]
public async Task OpenConnectionAsync()
{
Expand Down

0 comments on commit 2f95bb2

Please sign in to comment.