Skip to content

Commit 943a376

Browse files
committed
Reduce log message severity. Fixes #586
If the session is deliberately expired (via ClearAsync or ConnectionLifeTime) we shouldn't log a warning.
1 parent fa2ac3f commit 943a376

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,18 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
142142
}
143143
}
144144

145-
private bool SessionIsHealthy(ServerSession session)
145+
// Returns zero for healthy, non-zero otherwise.
146+
private int GetSessionHealth(ServerSession session)
146147
{
147148
if (!session.IsConnected)
148-
return false;
149+
return 1;
149150
if (session.PoolGeneration != m_generation)
150-
return false;
151+
return 2;
151152
if (ConnectionSettings.ConnectionLifeTime > 0
152153
&& unchecked((uint) Environment.TickCount) - session.CreatedTicks >= ConnectionSettings.ConnectionLifeTime)
153-
return false;
154+
return 3;
154155

155-
return true;
156+
return 0;
156157
}
157158

158159
public void Return(ServerSession session)
@@ -165,14 +166,18 @@ public void Return(ServerSession session)
165166
lock (m_leasedSessions)
166167
m_leasedSessions.Remove(session.Id);
167168
session.OwningConnection = null;
168-
if (SessionIsHealthy(session))
169+
var sessionHealth = GetSessionHealth(session);
170+
if (sessionHealth == 0)
169171
{
170172
lock (m_sessions)
171173
m_sessions.AddFirst(session);
172174
}
173175
else
174176
{
175-
Log.Warn("Pool{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
177+
if (sessionHealth == 1)
178+
Log.Warn("Pool{0} received invalid Session{1}; destroying it", m_logArguments[0], session.Id);
179+
else
180+
Log.Info("Pool{0} received expired Session{1}; destroying it", m_logArguments[0], session.Id);
176181
AdjustHostConnectionCount(session, -1);
177182
session.DisposeAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
178183
}

0 commit comments

Comments
 (0)