Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/MySqlConnector/MySqlClient/ConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public async Task<MySqlSession> GetSessionAsync(IOBehavior ioBehavior, Cancellat
}
else
{
// session is valid, reset if supported
if (m_connectionSettings.ConnectionReset)
{
await session.ResetConnectionAsync(m_connectionSettings, ioBehavior, cancellationToken).ConfigureAwait(false);
}
// pooled session is ready to be used; return it
return session;
}
Expand All @@ -58,10 +53,26 @@ public void Return(MySqlSession session)
{
try
{
var success = false;

if (session.PoolGeneration == m_generation)
{
try
{
// reset the connection upon returning it to the pool
if (m_connectionSettings.ConnectionReset)
session.ResetConnectionAsync(m_connectionSettings, IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
success = true;
}
catch (MySqlException)
{
}
}

if (success)
m_sessions.Enqueue(session);
else
session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).ConfigureAwait(false);
session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
}
finally
{
Expand Down
1 change: 1 addition & 0 deletions tests/SideBySide.New/ConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public async Task WaitTimeout()
csb.Pooling = true;
csb.MinimumPoolSize = 0;
csb.MaximumPoolSize = 1;
csb.ConnectionReset = false;
int serverThread;

using (var connection = new MySqlConnection(csb.ConnectionString))
Expand Down