Skip to content

Fix WAL file-handle leak in disk store recovery#89

Open
sven-n wants to merge 1 commit into
Build5Nines:mainfrom
sven-n:fix/disk-vocab-store-wal-handle
Open

Fix WAL file-handle leak in disk store recovery#89
sven-n wants to merge 1 commit into
Build5Nines:mainfrom
sven-n:fix/disk-vocab-store-wal-handle

Conversation

@sven-n
Copy link
Copy Markdown

@sven-n sven-n commented May 21, 2026

Summary

  • RecoverFromWalOrIndex in both BasicDiskVocabularyStore and BasicDiskVectorStore opened the WAL with using var fs = …, whose scope extends to method end. The subsequent File.WriteAllBytes(_walPath, …) then raced against the still-open handle and threw IOException("The process cannot access the file '…wal' because it is being used by another process.") on Windows.
  • Fix: scope the FileStream/BinaryReader in an explicit using (…) block so they are disposed before the truncating write.
  • The same bug pattern existed in both stores; only the vocabulary store version was hit first, masking the vector store one. Both are fixed in this PR.

Test plan

  • SharpVectorTest.DiskVectorDatabaseTests.AddAndGetText_PersistsToDisk passes (previously failed with the IOException above)
  • SharpVectorTest.DiskVectorDatabaseTests.Delete_RemovesFromIndexButKeepsFile passes (previously failed with the same IOException)
  • Full test suite (dotnet test src/SharpVectorTest) — 66/66 green on this branch
  • No production behavior change beyond WAL recovery; the on-disk format is unchanged

🤖 Generated with Claude Code

RecoverFromWalOrIndex in both BasicDiskVocabularyStore and
BasicDiskVectorStore opened the WAL file with `using var fs`, which
keeps the handle alive until the end of the method. The subsequent
File.WriteAllBytes(_walPath, ...) call then raced against that handle
on Windows and threw IOException("The process cannot access the file
... because it is being used by another process."), causing
AddAndGetText_PersistsToDisk and Delete_RemovesFromIndexButKeepsFile to
fail intermittently.

Scope the FileStream/BinaryReader in an explicit `using (...)` block so
they are disposed before the truncating write.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant