test: add failing test for evictSourceBlob unlink-vs-store TOCTOU

Adds an instrumentation seam (evictSourceBlobTestHook, fired after the
row-deletion transaction commits and before the content file is
unlinked) and a test that pauses eviction there while a concurrent
StoreSource for identical content bytes races it. Currently red: the
store completes immediately instead of being excluded, which is
exactly the window the review flagged between evictSourceBlob's commit
and its unlink.
This commit is contained in:
2026-08-09 00:45:39 +00:00
parent ea7621de29
commit 90b2f6fa66
3 changed files with 121 additions and 0 deletions

View File

@@ -318,6 +318,10 @@ func (c *Cache) evictSourceBlob(ctx context.Context, contentHash ContentHash) er
return fmt.Errorf("failed to commit eviction transaction: %w", err)
}
if c.evictSourceBlobTestHook != nil {
c.evictSourceBlobTestHook(contentHash)
}
// Only after the rows are gone may the files be removed.
for _, reference := range references {
if err := c.srcMetadata.Delete(reference.host, reference.pathHash); err != nil {