Skip to content
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

CloneWith ignores Pooling=false with connection from MySqlDataSource #1306

Closed
bgrainger opened this issue Apr 8, 2023 · 1 comment
Closed
Labels

Comments

@bgrainger
Copy link
Member

When a connection is obtained from a MySqlDataSource, cancelling a command executed on that connection uses a pooled connection to cancel. It should create and use a new non-pooled connection.

Repro code:

var loggerFactory = LoggerFactory.Create(builder =>
{
	builder.AddFilter("Microsoft", LogLevel.Information)
	   .AddFilter("System", LogLevel.Information)
	   .AddFilter("MySqlConnector", LogLevel.Trace)
	   .AddConsole();
});

var dataSource = new MySqlDataSourceBuilder("server=localhost;userid=root;password=pass")
	.UseLoggerFactory(loggerFactory)
	.Build();
using var connection = dataSource.OpenConnection();

using var command = new MySqlCommand("DO SLEEP(50);", connection);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2));
await command.ExecuteNonQueryAsync(cts.Token);

Log:

info: MySqlConnector.ConnectionPool[3001]
      Creating new connection pool 1 for Server=localhost;User ID=root
info: MySqlConnector.MySqlDataSource[1000]
      Data source 1 created with pool 1
trce: MySqlConnector.ConnectionPool[3000]
      Pool 1 waiting for an available session
trce: MySqlConnector.MySqlConnection[2000]
      Created new session 1.1
dbug: MySqlConnector.ConnectionPool[3018]
      Pool 1 has no pooled session available; created new session 1.1
trce: MySqlConnector.MySqlConnection[2122]
      Session 1.1 connecting to IP address ::1 (1 of 2) for host name localhost (1 of 1)
trce: MySqlConnector.MySqlConnection[2126]
      Session 1.1 connected to IP address ::1 for host name localhost with local port 61868
trce: MySqlConnector.MySqlConnection[2101]
      Session 1.1 server sent auth plugin name caching_sha2_password
dbug: MySqlConnector.MySqlConnection[2104]
      Session 1.1 made connection; server version 8.0.32; connection ID 9; supports: compression False, attributes True, deprecate EOF True, SSL True, session track True, pipelining True, query attributes True
trce: MySqlConnector.MySqlConnection[2131]
      Session 1.1 initializing TLS connection
dbug: MySqlConnector.MySqlConnection[2145]
      Session 1.1 connected TLS using Tls12 and TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
trce: MySqlConnector.MySqlConnection[2153]
      Session 1.1 creating connection attributes
trce: MySqlConnector.MySqlConnection[2115]
      Session 1.1 switching to authentication method caching_sha2_password
trce: MySqlConnector.ConnectionPool[3007]
      Pool 1 returning new session 1.1 to caller; 1 leased session(s)
trce: MySqlConnector.MySqlCommand[2202]
      Session 1.1 ExecuteReader Asynchronous for 1 command(s)
trce: MySqlConnector.MySqlCommand[2204]
      Session 1.1 preparing command payload for: DO SLEEP(50);
dbug: MySqlConnector.MySqlConnection[2304]
      Session 1.1 will cancel command 2 (1 attempts); CommandText: DO SLEEP(50);
dbug: MySqlConnector.MySqlConnection[2301]
      Command 2 for session 1.1 has been canceled via Cancel()
trce: MySqlConnector.ConnectionPool[3000]
      Pool 1 waiting for an available session
trce: MySqlConnector.MySqlConnection[2000]
      Created new session 1.2
dbug: MySqlConnector.ConnectionPool[3018]
      Pool 1 has no pooled session available; created new session 1.2
trce: MySqlConnector.MySqlConnection[2122]
      Session 1.2 connecting to IP address ::1 (1 of 2) for host name localhost (1 of 1)
trce: MySqlConnector.MySqlConnection[2126]
      Session 1.2 connected to IP address ::1 for host name localhost with local port 61869
trce: MySqlConnector.MySqlConnection[2101]
      Session 1.2 server sent auth plugin name caching_sha2_password
dbug: MySqlConnector.MySqlConnection[2104]
      Session 1.2 made connection; server version 8.0.32; connection ID 10; supports: compression False, attributes True, deprecate EOF True, SSL True, session track True, pipelining True, query attributes True
trce: MySqlConnector.MySqlConnection[2131]
      Session 1.2 initializing TLS connection
dbug: MySqlConnector.MySqlConnection[2145]
      Session 1.2 connected TLS using Tls12 and TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
trce: MySqlConnector.MySqlConnection[2115]
      Session 1.2 switching to authentication method caching_sha2_password
trce: MySqlConnector.ConnectionPool[3007]
      Pool 1 returning new session 1.2 to caller; 2 leased session(s)
info: MySqlConnector.MySqlConnection[2305]
      Session 1.1 canceling command 2 from session 1.2; CommandText: DO SLEEP(50);
dbug: MySqlConnector.MySqlConnection[2307]
      Session 1.2 canceling command 2 with text KILL QUERY 9
trce: MySqlConnector.MySqlCommand[2202]
      Session 1.2 ExecuteReader Synchronous for 1 command(s)
trce: MySqlConnector.MySqlCommand[2204]
      Session 1.2 preparing command payload for: KILL QUERY 9
trce: MySqlConnector.MySqlConnection[2201]
      Session 1.1 entering FinishQuerying; state is CancelingQuery
trce: MySqlConnector.MySqlConnection[2201]
      Session 1.2 entering FinishQuerying; state is Querying
dbug: MySqlConnector.MySqlConnection[2308]
      Session 1.1 sending 'SLEEP(0)' command to clear pending cancellation
trce: MySqlConnector.MySqlConnection[2003]
      Session 1.2 returning to pool 1
trce: MySqlConnector.ConnectionPool[3010]
      Pool 1 receiving session 1.2 back
trce: MySqlConnector.MySqlConnection[2003]
      Session 1.1 returning to pool 1
trce: MySqlConnector.ConnectionPool[3010]
      Pool 1 receiving session 1.1 back
trce: MySqlConnector.ConnectionPool[3100]
      Pool 1 reaping connection pool
trce: MySqlConnector.ConnectionPool[3015]
      Pool 1 recovered no sessions
@bgrainger
Copy link
Member Author

A simpler repro is:

using var connection = dataSource.OpenConnection();
using var connection2 = connection.CloneWith("Pooling=false");
connection2.Open();

@bgrainger bgrainger changed the title Cancelling uses pooled connection with MySqlDataSource CloneWith ignores Pooling=false with connection from MySqlDataSource Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant