Skip to content

Commit 1f44c6f

Browse files
committed
Remove BackgroundConnectionResetHelper. Fixes #1013
1 parent ec6ccdd commit 1f44c6f

File tree

7 files changed

+13
-131
lines changed

7 files changed

+13
-131
lines changed

src/MySqlConnector/Core/BackgroundConnectionResetHelper.cs

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

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async ValueTask<ServerSession> GetSessionAsync(MySqlConnection connection
6666
}
6767
else
6868
{
69-
if ((ConnectionSettings.ConnectionReset && ConnectionSettings.DeferConnectionReset) || session.DatabaseOverride is not null)
69+
if (ConnectionSettings.ConnectionReset || session.DatabaseOverride is not null)
7070
{
7171
reuseSession = await session.TryResetConnectionAsync(ConnectionSettings, null, false, ioBehavior, cancellationToken).ConfigureAwait(false);
7272
}
@@ -482,9 +482,6 @@ private async ValueTask<ServerSession> ConnectSessionAsync(string logMessage, in
482482
// if we won the race to create the new pool, also store it under the original connection string
483483
if (connectionString != normalizedConnectionString)
484484
s_pools.GetOrAdd(connectionString, pool);
485-
486-
if (connectionSettings.ConnectionReset)
487-
BackgroundConnectionResetHelper.Start();
488485
}
489486
else if (pool != newPool && Log.IsDebugEnabled())
490487
{
@@ -609,7 +606,6 @@ static ConnectionPool()
609606
static void OnAppDomainShutDown(object? sender, EventArgs e)
610607
{
611608
ClearPoolsAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
612-
BackgroundConnectionResetHelper.Stop();
613609
}
614610
#endif
615611

src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Net.Security;
55
using System.Security.Authentication;
6+
using MySqlConnector.Logging;
67
using MySqlConnector.Utilities;
78

89
namespace MySqlConnector.Core
@@ -114,7 +115,10 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
114115
ConnectionReset = csb.ConnectionReset;
115116
ConnectionIdlePingTime = Math.Min(csb.ConnectionIdlePingTime, uint.MaxValue / 1000) * 1000;
116117
ConnectionIdleTimeout = (int) csb.ConnectionIdleTimeout;
117-
DeferConnectionReset = csb.DeferConnectionReset;
118+
#pragma warning disable 618
119+
if (!csb.DeferConnectionReset)
120+
Log.Warn("DeferConnectionReset=false is not supported; using regular connection reset behavior.");
121+
#pragma warning restore 618
118122
if (csb.MinimumPoolSize > csb.MaximumPoolSize)
119123
throw new MySqlException("MaximumPoolSize must be greater than or equal to MinimumPoolSize");
120124
MinimumPoolSize = ToSigned(csb.MinimumPoolSize);
@@ -211,7 +215,6 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
211215
public bool ConnectionReset { get; }
212216
public uint ConnectionIdlePingTime { get; }
213217
public int ConnectionIdleTimeout { get; }
214-
public bool DeferConnectionReset { get; }
215218
public int MinimumPoolSize { get; }
216219
public int MaximumPoolSize { get; }
217220

@@ -328,6 +331,7 @@ private ConnectionSettings(ConnectionSettings other, string host, int port, stri
328331
UseXaTransactions = other.UseXaTransactions;
329332
}
330333

334+
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(ConnectionSettings));
331335
static readonly string[] s_localhostPipeServer = { "." };
332336
}
333337
}

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ public ValueTask<int> ReturnToPoolAsync(IOBehavior ioBehavior, MySqlConnection?
8080
Log.Trace("Session{0} returning to Pool{1}", m_logArguments);
8181
}
8282
LastReturnedTicks = unchecked((uint) Environment.TickCount);
83-
if (Pool is null)
84-
return default;
85-
if (!Pool.ConnectionSettings.ConnectionReset || Pool.ConnectionSettings.DeferConnectionReset)
86-
return Pool.ReturnAsync(ioBehavior, this);
87-
BackgroundConnectionResetHelper.AddSession(this, owningConnection);
88-
return default;
83+
return Pool is null ? default : Pool.ReturnAsync(ioBehavior, this);
8984
}
9085

9186
public bool IsConnected

src/MySqlConnector/MySqlConnectionStringBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public uint ConnectionIdleTimeout
181181
set => MySqlConnectionStringOption.ConnectionIdleTimeout.SetValue(this, value);
182182
}
183183

184+
[Obsolete("This option is no longer supported in MySqlConnector >= 1.4.0.")]
184185
public bool DeferConnectionReset
185186
{
186187
get => MySqlConnectionStringOption.DeferConnectionReset.GetValue(this);

tests/MySqlConnector.Tests/MySqlConnectionStringBuilderTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public void Defaults()
3636
Assert.False(csb.ConnectionReset);
3737
#else
3838
Assert.True(csb.ConnectionReset);
39+
#pragma warning disable 618
3940
Assert.True(csb.DeferConnectionReset);
41+
#pragma warning restore 618
4042
#endif
4143
Assert.Equal(15u, csb.ConnectionTimeout);
4244
Assert.False(csb.ConvertZeroDateTime);
@@ -186,7 +188,9 @@ public void ParseConnectionString()
186188
Assert.Equal("My Test Application", csb.ApplicationName);
187189
Assert.Equal(60u, csb.ConnectionIdlePingTime);
188190
Assert.Equal(30u, csb.ConnectionIdleTimeout);
191+
#pragma warning disable 618
189192
Assert.True(csb.DeferConnectionReset);
193+
#pragma warning restore 618
190194
Assert.True(csb.ForceSynchronous);
191195
Assert.True(csb.IgnoreCommandTransaction);
192196
Assert.Equal("rsa.pem", csb.ServerRsaPublicKeyFile);

tests/SideBySide/ConnectionPool.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ public async Task WaitTimeout()
155155
csb.Pooling = true;
156156
csb.MinimumPoolSize = 0;
157157
csb.MaximumPoolSize = 1;
158-
#if !BASELINE
159-
csb.DeferConnectionReset = true;
160-
#endif
161158
int serverThread;
162159

163160
using (var connection = new MySqlConnection(csb.ConnectionString))

0 commit comments

Comments
 (0)