-
-
Notifications
You must be signed in to change notification settings - Fork 10
fix: cleanup legacy narinfo in PutNarInfo to avoid race condition #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: cleanup legacy narinfo in PutNarInfo to avoid race condition #658
Conversation
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical race condition that could lead to storage inconsistencies. By proactively cleaning up legacy narinfo files during the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request addresses a race condition in PutNarInfo that could lead to storage inconsistency. It adds an explicit check for legacy narinfo files in storage and deletes them after the database update. This ensures consistency regardless of the order in which GetNarInfo and PutNarInfo calls complete. The change appears to be well-reasoned and effectively mitigates the identified issue.
In a thundering herd scenario where multiple concurrent GetNarInfo and PutNarInfo calls occur for the same hash, PutNarInfo might commit to the database before GetNarInfo triggers a migration. This skips the migration logic, leaving legacy narinfo files in storage, which causes tests to fail and leads to storage inconsistency. This change adds an explicit check for legacy narinfo files in PutNarInfo. If a file exists in the storage backend after the database update, it is now deleted. This ensures consistency regardless of which operation finishes first. I have also added a deterministic test that uses hooks to force this race condition and verify that the cleanup always occurs.
7746d9a to
a39997f
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a race condition between GetNarInfo and PutNarInfo by ensuring legacy narinfo files are cleaned up from storage. The fix in PutNarInfo is straightforward and correctly placed. The addition of a deterministic test (TestGetNarInfo_RaceWithPutNarInfoDeterministic) is excellent, as it reliably reproduces the race condition using a clever hook, providing strong confidence in the fix. I have one suggestion to make the logging less noisy in certain race scenarios, but overall this is a high-quality contribution.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses a race condition between GetNarInfo and PutNarInfo by ensuring PutNarInfo cleans up legacy narinfo files from storage. The fix is clean, well-commented, and directly solves the described problem. The addition of a deterministic test (TestGetNarInfo_RaceWithPutNarInfoDeterministic) is excellent; it's thorough and correctly simulates the complex race condition to verify the fix. I have one suggestion to make the new test slightly more robust against future changes.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

In a thundering herd scenario where multiple concurrent GetNarInfo and PutNarInfo calls occur for the same hash, PutNarInfo might commit to the database before GetNarInfo triggers a migration. This skips the migration logic, leaving legacy narinfo files in storage, which causes tests to fail and leads to storage inconsistency.
This change adds an explicit check for legacy narinfo files in PutNarInfo. If a file exists in the storage backend after the database update, it is now deleted. This ensures consistency regardless of which operation finishes first.
I have also added a deterministic test that uses hooks to force this race condition and verify that the cleanup always occurs.