Skip to content

Commit

Permalink
Reduce log message severity. Fixes #586
Browse files Browse the repository at this point in the history
If the session is deliberately expired (via ClearAsync or ConnectionLifeTime) we shouldn't log a warning.
  • Loading branch information
bgrainger committed Dec 2, 2018
1 parent fa2ac3f commit 943a376
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/MySqlConnector/Core/ConnectionPool.cs
Expand Up @@ -142,17 +142,18 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
}
}

private bool SessionIsHealthy(ServerSession session)
// Returns zero for healthy, non-zero otherwise.
private int GetSessionHealth(ServerSession session)
{
if (!session.IsConnected)
return false;
return 1;
if (session.PoolGeneration != m_generation)
return false;
return 2;
if (ConnectionSettings.ConnectionLifeTime > 0
&& unchecked((uint) Environment.TickCount) - session.CreatedTicks >= ConnectionSettings.ConnectionLifeTime)
return false;
return 3;

return true;
return 0;
}

public void Return(ServerSession session)
Expand All @@ -165,14 +166,18 @@ public void Return(ServerSession session)
lock (m_leasedSessions)
m_leasedSessions.Remove(session.Id);
session.OwningConnection = null;
if (SessionIsHealthy(session))
var sessionHealth = GetSessionHealth(session);
if (sessionHealth == 0)
{
lock (m_sessions)
m_sessions.AddFirst(session);
}
else
{
Log.Warn("Pool{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
if (sessionHealth == 1)
Log.Warn("Pool{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
else
Log.Info("Pool{0} received expired Session{1}; destroying it", m_logArguments[0], session.Id);
AdjustHostConnectionCount(session, -1);
session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
}
Expand Down

0 comments on commit 943a376

Please sign in to comment.