-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using Connection Pooling, it is not possible to send a Validation Query. #1474
Comments
There's currently no way to force every connection in the pool to send a query.
Can you control the Alternatively, if you know there are exactly three connections in the pool, you could try something like: // open all three connections from the pool at once
using (var connection1 = new MySqlConnection(builder.ConnectionString))
using (var connection2 = new MySqlConnection(builder.ConnectionString))
using (var connection3 = new MySqlConnection(builder.ConnectionString))
{
// send a message on each open connection
connection1.Ping();
connection2.Ping();
connection3.Ping();
} (with appropriate error handling for failing to retrieve a connection from the pool in time) |
In the case of wait_timeout,
The method you proposed seems to have an issue where all sessions in the connection pool change synchronously in an instant. I believe ValidationQuery is a very good method that can cover many database environments. Upon examining the library internals, it appears that there is already a scheduler running within the ConnectionPool. |
I don't know what this means, sorry.
That documentation says, "The SQL query that will be used to validate connections from this pool before returning them to the caller." It doesn't imply AFAICT that the ValidationQuery will be run periodically in the background. Is that what the |
From what I understand, the scenario that changes synchronously is as follows: When the connection pool has a minimum of 3 and a maximum of 3 connections:
At this point, it becomes synchronous. From Thread A's perspective:
From Thread B's perspective:
In this way, it changes synchronously. |
I'm sorry for the confusion. The intention behind the provided link was to explain the use of Validation Query for checking the connection state, not necessarily suggesting that the feature should run in the background. Let me re-propose the feature: What do you think about this proposed feature? |
It's interesting, but I don't see the benefit over Back to the OP:
Are you observing this MySqlConnector/src/MySqlConnector/Core/ServerSession.cs Lines 644 to 647 in bc6785e
What should be happening is that MySqlConnector detects an invalid connection in the pool and transparently creates and returns a new one to you. Are you not seeing that happen? |
Software versions
MySqlConnector version: 2.3.7
Server type (MySQL, MariaDB, Aurora, etc.) and version: MySql 8.0.3
.NET version: .net 8.0
(Optional) ORM NuGet packages and versions: Dapper 2.1.44
Describe the bug
We are using the ConnectionPool feature.
We are maintaining three sessions.
However, the Validation Query(SELECT 1) should be used by all three sessions, but due to pooling, it cannot be used in the remaining two sessions.
As a result of this issue, sessions keep getting disconnected due to the wait_timeout.
How can we send the Validation Query to all sessions?
Exception
Full exception message and call stack (if applicable)
Code sample
Expected behavior
A clear and concise description of what you expected to happen.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: