Skip to content

Commit e3d4f80

Browse files
committed
Remove ConnectionIdlePingTime behaviour. Fixes #1042
- 'Connection Reset = True' will perform a server roundtrip to reset the connection. - 'Connection Reset = False' will return a connection from the pool (if one exists); the client should use appropriate retry logic to reopen the connection if the first communication with the server fails. Signed-off-by: Bradley Grainger <[email protected]>
1 parent 5187e98 commit e3d4f80

File tree

7 files changed

+6
-53
lines changed

7 files changed

+6
-53
lines changed

docs/content/api/MySqlConnector/MySqlConnectionStringBuilder/ConnectionIdlePingTime.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/content/api/MySqlConnector/MySqlConnectionStringBuilderType.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public sealed class MySqlConnectionStringBuilder : DbConnectionStringBuilder
2828
| [CertificateStoreLocation](../MySqlConnectionStringBuilder/CertificateStoreLocation/) { getset; } | Uses a certificate from the specified Certificate Store on the machine. The default value of None means the certificate store is not used; a value of CurrentUser or LocalMachine uses the specified store. |
2929
| [CertificateThumbprint](../MySqlConnectionStringBuilder/CertificateThumbprint/) { getset; } | Specifies which certificate should be used from the Certificate Store specified in [`CertificateStoreLocation`](../MySqlConnectionStringBuilder/CertificateStoreLocation/). This option must be used to indicate which certificate in the store should be used for authentication. |
3030
| [CharacterSet](../MySqlConnectionStringBuilder/CharacterSet/) { getset; } | Supported for backwards compatibility; MySqlConnector always uses `utf8mb4`. |
31-
| [ConnectionIdlePingTime](../MySqlConnectionStringBuilder/ConnectionIdlePingTime/) { getset; } | The delay (in seconds) before idle connections are pinged (to determine liveness) when being retrieved from the pool. |
3231
| [ConnectionIdleTimeout](../MySqlConnectionStringBuilder/ConnectionIdleTimeout/) { getset; } | The amount of time (in seconds) that a connection can remain idle in the pool. |
3332
| [ConnectionLifeTime](../MySqlConnectionStringBuilder/ConnectionLifeTime/) { getset; } | The maximum lifetime (in seconds) for any connection, or `0` for no lifetime limit. |
3433
| [ConnectionProtocol](../MySqlConnectionStringBuilder/ConnectionProtocol/) { getset; } | The protocol to use to connect to the MySQL Server. |

docs/content/connection-options.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,7 @@ Connection pooling is enabled by default. These options are used to configure it
169169
<tr id="ConnectionReset">
170170
<td>Connection Reset, ConnectionReset</td>
171171
<td><code>true</code></td>
172-
<td>If <code>true</code>, all connections retrieved from the pool will have been reset. The default value of <code>true</code> ensures that the connection is in the same state whether it’s newly created or retrieved from the pool. A value of <code>false</code> avoids making an additional server round trip to reset the connection, but the connection state is not reset, meaning that session variables and other session state changes from any previous use of the connection are carried over.</td>
173-
</tr>
174-
<tr id="ConnectionIdlePingTime">
175-
<td>Connection Idle Ping Time, ConnectionIdlePingTime <em>(Experimental)</em></td>
176-
<td>0</td>
177-
<td>When a connection is retrieved from the pool, and <code>ConnectionReset</code> is <code>false</code>, the server
178-
will be pinged if the connection has been idle in the pool for longer than <code>ConnectionIdlePingTime</code> seconds.
179-
If pinging the server fails, a new connection will be opened automatically by the connection pool. This ensures that the
180-
<code>MySqlConnection</code> is in a valid, open state after the call to <code>Open</code>/<code>OpenAsync</code>,
181-
at the cost of an extra server roundtrip. For high-performance scenarios, you may wish to set <code>ConnectionIdlePingTime</code>
182-
to a non-zero value to make the connection pool assume that recently-returned connections are still open. If the
183-
connection is broken, it will throw from the first call to <code>ExecuteNonQuery</code>, <code>ExecuteReader</code>,
184-
etc.; your code should handle that failure and retry the connection. This option has no effect if <code>ConnectionReset</code>
185-
is <code>true</code>, as that will cause a connection reset packet to be sent to the server, making ping redundant.
172+
<td>If <code>true</code>, all connections retrieved from the pool will have been reset. The default value of <code>true</code> ensures that the connection is in the same state whether it’s newly created or retrieved from the pool. A value of <code>false</code> avoids making an additional server round trip to reset the connection, but the connection state is not reset, meaning that session variables and other session state changes from any previous use of the connection are carried over. Additionally (if <code>Connection Reset</code> is <code>false</false>), when <code>MySqlConnection.Open</code> returns a connection from the pool (instead of opening a new one), the connection may be invalid (and throw an exception on first use) if the server has closed the connection.</td>
186173
</tr>
187174
<tr id="ConnectionIdleTimeout">
188175
<td>Connection Idle Timeout, ConnectionIdleTimeout</td>

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
6767
else
6868
{
6969
if (ConnectionSettings.ConnectionReset || session.DatabaseOverride is not null)
70-
{
7170
reuseSession = await session.TryResetConnectionAsync(ConnectionSettings, null, false, ioBehavior, cancellationToken).ConfigureAwait(false);
72-
}
73-
else if ((unchecked((uint) Environment.TickCount) - session.LastReturnedTicks) >= ConnectionSettings.ConnectionIdlePingTime)
74-
{
75-
reuseSession = await session.TryPingAsync(logInfo: false, ioBehavior, cancellationToken).ConfigureAwait(false);
76-
}
7771
else
78-
{
7972
reuseSession = true;
80-
}
8173
}
8274

8375
if (!reuseSession)

src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
112112
Pooling = csb.Pooling;
113113
ConnectionLifeTime = Math.Min(csb.ConnectionLifeTime, uint.MaxValue / 1000) * 1000;
114114
ConnectionReset = csb.ConnectionReset;
115-
ConnectionIdlePingTime = Math.Min(csb.ConnectionIdlePingTime, uint.MaxValue / 1000) * 1000;
116115
ConnectionIdleTimeout = (int) csb.ConnectionIdleTimeout;
117116
#pragma warning disable 618
118117
if (!csb.DeferConnectionReset)
@@ -212,7 +211,6 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
212211
public bool Pooling { get; }
213212
public uint ConnectionLifeTime { get; }
214213
public bool ConnectionReset { get; }
215-
public uint ConnectionIdlePingTime { get; }
216214
public int ConnectionIdleTimeout { get; }
217215
public int MinimumPoolSize { get; }
218216
public int MaximumPoolSize { get; }
@@ -298,7 +296,6 @@ private ConnectionSettings(ConnectionSettings other, string host, int port, stri
298296
Pooling = other.Pooling;
299297
ConnectionLifeTime = other.ConnectionLifeTime;
300298
ConnectionReset = other.ConnectionReset;
301-
ConnectionIdlePingTime = other.ConnectionIdlePingTime;
302299
ConnectionIdleTimeout = other.ConnectionIdleTimeout;
303300
MinimumPoolSize = other.MinimumPoolSize;
304301
MaximumPoolSize = other.MaximumPoolSize;

src/MySqlConnector/MySqlConnectionStringBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ public bool ConnectionReset
339339
}
340340

341341
/// <summary>
342-
/// The delay (in seconds) before idle connections are pinged (to determine liveness) when being retrieved from the pool.
342+
/// This option is no longer supported.
343343
/// </summary>
344-
[Category("Pooling")]
344+
[Category("Obsolete")]
345345
[DefaultValue(0u)]
346-
[Description("The delay (in seconds) before idle connections are pinged (to determine liveness) when being retrieved from the pool.")]
347346
[DisplayName("Connection Idle Ping Time")]
347+
[Obsolete("This option is no longer supported in MySqlConnector >= 1.4.0.")]
348348
public uint ConnectionIdlePingTime
349349
{
350350
get => MySqlConnectionStringOption.ConnectionIdlePingTime.GetValue(this);
@@ -368,8 +368,8 @@ public uint ConnectionIdleTimeout
368368
/// This option is no longer supported.
369369
/// </summary>
370370
[Category("Obsolete")]
371-
[DisplayName("Defer Connection Reset")]
372371
[DefaultValue(true)]
372+
[DisplayName("Defer Connection Reset")]
373373
[Obsolete("This option is no longer supported in MySqlConnector >= 1.4.0.")]
374374
public bool DeferConnectionReset
375375
{

tests/MySqlConnector.Tests/MySqlConnectionStringBuilderTests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public void Defaults()
3939
#else
4040
Assert.True(csb.ConnectionReset);
4141
#pragma warning disable 618
42+
Assert.Equal(0u, csb.ConnectionIdlePingTime);
4243
Assert.True(csb.DeferConnectionReset);
4344
#pragma warning restore 618
4445
#endif
@@ -51,7 +52,6 @@ public void Defaults()
5152
Assert.Equal(30u, csb.DefaultCommandTimeout);
5253
#if !BASELINE
5354
Assert.Equal("", csb.ApplicationName);
54-
Assert.Equal(0u, csb.ConnectionIdlePingTime);
5555
Assert.Equal(180u, csb.ConnectionIdleTimeout);
5656
Assert.False(csb.ForceSynchronous);
5757
Assert.Equal(MySqlGuidFormat.Default, csb.GuidFormat);
@@ -127,7 +127,6 @@ public void ParseConnectionString()
127127
#if !BASELINE
128128
"application name=My Test Application;" +
129129
"cancellation timeout = -1;" +
130-
"connection idle ping time=60;" +
131130
"connectionidletimeout=30;" +
132131
"defer connection reset=true;" +
133132
"forcesynchronous=true;" +
@@ -188,7 +187,6 @@ public void ParseConnectionString()
188187
Assert.Equal(123u, csb.DefaultCommandTimeout);
189188
#if !BASELINE
190189
Assert.Equal("My Test Application", csb.ApplicationName);
191-
Assert.Equal(60u, csb.ConnectionIdlePingTime);
192190
Assert.Equal(30u, csb.ConnectionIdleTimeout);
193191
#pragma warning disable 618
194192
Assert.True(csb.DeferConnectionReset);
@@ -499,7 +497,6 @@ public void ParseInvalidTlsVersion()
499497
// not supported
500498
[InlineData("Application Name", "MyApp")]
501499
[InlineData("Cancellation Timeout", 5)]
502-
[InlineData("Connection Idle Ping Time", 100u)]
503500
[InlineData("Connection Idle Timeout", 10u)]
504501
[InlineData("DateTime Kind", MySqlDateTimeKind.Utc)]
505502
[InlineData("Force Synchronous", true)]

0 commit comments

Comments
 (0)