Commit cb9b366
Sync bbolt databases on close to prevent corruption
When bbolt is opened with NoSync: true, transactions complete in memory
without fsync to disk. On graceful shutdown, dirty pages in the OS page
cache may not be flushed before Close() returns, leading to corruption
when the filesystem is unmounted or snapshots are taken.
This is particularly problematic with network block devices (Ceph RBD)
and container snapshot workflows where:
1. BuildKit stops gracefully (SIGTERM)
2. Close() returns without syncing dirty pages
3. Unmount forces writeback of partial/torn pages
4. Snapshot captures inconsistent B-tree state
The fix wraps bolt.DB with syncingDB that calls Sync() before Close(),
ensuring all pending writes are flushed to disk during graceful shutdown
while preserving the NoSync performance benefits during normal operation.
Signed-off-by: Aditya Maru <adityamaru@gmail.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 0a4bb7d commit cb9b366
1 file changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
10 | 35 | | |
11 | 36 | | |
12 | 37 | | |
13 | 38 | | |
14 | 39 | | |
15 | | - | |
| 40 | + | |
16 | 41 | | |
0 commit comments