The following code executes a 60 second SQL with a 5 second command timeout.
On both .Net Framework 4.8 and .Net 7.0 this correctly throws a TimeoutException after 5 seconds.
However on .Net7.0 the command is cancelled on the DB but .Net Framework 4.8 the command is left running
Reproducible in both the latest 7.0.6 Npgsql package and the current 8.0 rc2 package
Seems to have been introduced somewhere around NpgSsql 6.0
(PostgreSQL 15.4 on AWS RDS, Windows 10)
var datasource = builder.Build();
var conn = datasource.CreateConnection();
conn.Open();
NpgsqlCommand command = conn.CreateCommand();
command.CommandTimeout = 5;
Stopwatch sw = Stopwatch.StartNew();
command.CommandText = "select pg_sleep(60)";
try {
command.ExecuteReader(CommandBehavior.SingleResult);
} catch (Exception) {
}
Debug.WriteLine($"z: {sw.ElapsedMilliseconds}");
The following code executes a 60 second SQL with a 5 second command timeout.
On both .Net Framework 4.8 and .Net 7.0 this correctly throws a TimeoutException after 5 seconds.
However on .Net7.0 the command is cancelled on the DB but .Net Framework 4.8 the command is left running
Reproducible in both the latest 7.0.6 Npgsql package and the current 8.0 rc2 package
Seems to have been introduced somewhere around NpgSsql 6.0
(PostgreSQL 15.4 on AWS RDS, Windows 10)