Closed
Description
SqlCommand.Cancel()
doesn't appear to work using System.Data.SqlClient on Linux (Ubuntu 19.04, .NET Core SDK 3.0.100-preview5-011568) - the command runs to completion, and only then throws SqlException. The issue does not seem to repro on Windows (with .NET Core).
Repro:
using (var cmd = new SqlCommand("WAITFOR DELAY '00:00:05'", conn))
{
// sync cancellation
Task.Delay(1000).ContinueWith(t => cmd.Cancel());
var sw = Stopwatch.StartNew();
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Console.WriteLine($"Sync cancellation: caught {e.GetType().Name} after {sw.ElapsedMilliseconds}ms");
// Does not interrupt the call (completes after 5 seconds) but still generates SqlException at the end
}
// async cancellation
sw.Restart();
try
{
await cmd.ExecuteNonQueryAsync(new CancellationTokenSource(1000).Token);
}
catch (Exception e)
{
Console.WriteLine($"Async cancellation: caught {e.GetType().Name} after {sw.ElapsedMilliseconds}ms");
// Interrupts and generates SqlException immediately
}
}
/cc @divega @karinazhou
Metadata
Metadata
Assignees
Labels
No labels