Skip to content

Connection pool leak #836

Closed
Closed
@alexalok

Description

@alexalok

I have faced an "Too Many Connections" exception and while working on a fix have noticed that one of the queries was sometimes timing out (cause is not related to the library). That query runs periodically and opens a new connection on every run. Since we have a pooling mechanism enabled, it usually just grabs one of the pool connections and releases it after some time. However if query times out then the pool connection is not released. Please see the following extract from the logs:

...
2020/06/23 15:15:01.179|INFO|ServerSession|Session1.1 failed in ReceiveReplyAsync|The Command Timeout expired before the operation completed.
2020/06/23 15:15:01.179|INFO|ServerSession|Session1.1 setting state to Failed|The Command Timeout expired before the operation completed.
2020/06/23 15:15:01.179|INFO|ServerSession|Session1.1 setting state to Failed|The Command Timeout expired before the operation completed.
2020/06/23 15:15:01.179|DEBUG|ServerSession|Session1.1 entering FinishQuerying; SessionState=Failed|
2020/06/23 15:15:02.100|DEBUG|ConnectionPool|Pool1 reaping connection pool|
2020/06/23 15:15:02.100|DEBUG|ConnectionPool|Pool1 recovered no sessions|
2020/06/23 15:15:03.193|DEBUG|ConnectionPool|Pool1 waiting for an available session|
2020/06/23 15:15:03.193|DEBUG|ConnectionPool|Pool1 found an existing session; checking it for validity|
2020/06/23 15:15:03.193|DEBUG|ServerSession|Session1.3 ServerVersion=8.0.19 supports reset connection; sending reset connection request|
2020/06/23 15:15:03.193|DEBUG|ConnectionPool|Pool1 returning pooled Session1.3 to caller; LeasedSessionsCount=3|
...

As you can see, Session1.1 is in a failed state now but it still counts in LeasedSessionsCount. After some time, more and more pool connections move to a failed state and accumulate in LeasedSessionsCount until the limit is reached. I also believe those connections are in a closed state because I do not see a gradual increase in active connections on the server's side.

Perhaps I'm missing something and there is a setting to force such connections to be reaped as well? I would appreciate any feedback on this matter.


MySqlConnector version: 0.61.0
MySQL server version: 8.0.19
.NET version: .NET Core 3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions