Skip to content

No exception when db command cancelled #2666

@standsed

Description

@standsed

Sometimes no exception is thrown when

But in short: out of 60 iterations of code fragment below exception is thrown 50 times. No records are inserted with value "2"

const int timeoutSeconds = 1;
context.Database.SetCommandTimeout(timeoutSeconds);
await context.Database.ExecuteSqlRawAsync(
        """
        INSERT INTO MyEntity VALUES (1);
        WAITFOR DELAY '00:00:02';
        INSERT INTO MyEntity VALUES (2);
""", CreateCancellationToken(TimeSpan.FromSeconds(timeoutSeconds)));

Version information

Microsoft.EntityFrameworkCore Version="8.0.6"
Microsoft.EntityFrameworkCore.SqlServer Version="8.0.6"
TargetFramework net8.0
Operating system: Windows 10
SQL Server 2022 (docker image mcr.microsoft.com/mssql/server 994123c66ce4)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Repro Available ✔️Issues that are reproducible with repro provided.

    Type

    No fields configured for Bug.

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions