Skip to content

CommandTimeout on classic .Net Framework ExecuteReader leaves command executing on DB #5356

Description

@johnfedak

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}");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions