No exception when db command cancelled
- Dominant language
- C#
- Stars
- 989
- Forks
- 340
- Avg merge
- 4d 19h
- Merged PRs (30d)
- 72
Description
Sometimes no exception is thrown when
- db command timeout is breached
- cancellation token is cancelled the same moment when db command timeout is breached.
Reproduced in https://github.com/standsed/EFTimeoutRepro/blob/main/Program.cs
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)
Contributor guide
Assessment
This issue has not been assessed yet.