This repository contains a reproducible example of a bug in rollback handling in Microsoft.Data.Sqlite when using pattern is used for managing lifetime of SqliteTransaction.
The issue occurs for any solution that uses Microsoft.Data.Sqlite including Entity Framework Core or Dapper when the disk space is low.
Win + Rto open the Run dialog, typems-settings:storagesenseto open storage settings. Disable "Storage Sense" to prevent automatic cleanup of temporary files.- Adjust the
Program.DatabaseFilePathconstant to point to a Sqlite database file. If the file does not exist, it will be created. To speedup reproduction, it's recommended to point to a file on a disk with small empty space. - Run the app and choose one of the options:
- "1" - Uses EF Core. Catches and outputs the real error returned by SQLite.
- "2" - Uses EF Core without catching nested "real" error. It represents the code and error handling that is common with
usingpattern. - "3" - Uses Dapper. Catches and outputs the real error returned by SQLite.
- "4" - Uses Dapper without catching nested "real" error. It represents the code and error handling that is common with
usingpattern.
- The app will append rows to the database in loop until it runs out of disk space. Each transaction consists of 5 rows with 100 KB of data each.
- When the disk is full, Sqlite will throw an exception.
The app will log to console the original exception and the one that's propagated from the
usingblock.