Skip to content

Commit 6269009

Browse files
committed
Clear connection pools on exit. Fixes #545
1 parent 91f5068 commit 6269009

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,16 @@ public ConnectionStringPool(string connectionString, ConnectionPool pool)
517517
public ConnectionPool Pool { get; }
518518
}
519519

520+
#if !NETSTANDARD1_3
521+
static ConnectionPool()
522+
{
523+
AppDomain.CurrentDomain.DomainUnload += OnAppDomainShutDown;
524+
AppDomain.CurrentDomain.ProcessExit += OnAppDomainShutDown;
525+
}
526+
527+
static void OnAppDomainShutDown(object sender, EventArgs e) => ClearPoolsAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
528+
#endif
529+
520530
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(ConnectionPool));
521531
static readonly ConcurrentDictionary<string, ConnectionPool> s_pools = new ConcurrentDictionary<string, ConnectionPool>();
522532

0 commit comments

Comments
 (0)