Skip to content

Conversation

@kalbasit
Copy link
Owner

@kalbasit kalbasit commented Jan 26, 2026

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.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jan 26, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 PutNarInfo operation, it guarantees that the storage state remains consistent, regardless of the timing of concurrent operations, thereby preventing test failures and maintaining data integrity.

Highlights

  • Race Condition Fix: Addresses a race condition in PutNarInfo where legacy narinfo files could persist in storage if PutNarInfo completed before a background migration, leading to storage inconsistency and test failures.
  • Explicit Legacy Narinfo Cleanup: Introduces an explicit check and deletion mechanism within PutNarInfo to remove legacy narinfo files from the storage backend after the database update, ensuring consistency regardless of the timing of concurrent operations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added bug Something isn't working go Pull requests that update go code labels Jan 26, 2026
Copy link
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.
@kalbasit kalbasit force-pushed the 01-26-fix_cleanup_legacy_narinfo_in_putnarinfo_to_avoid_race_condition branch from 7746d9a to a39997f Compare January 26, 2026 09:14
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jan 26, 2026
@kalbasit
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@kalbasit
Copy link
Owner Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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>
@kalbasit kalbasit enabled auto-merge (squash) January 26, 2026 09:29
@kalbasit kalbasit merged commit 2223a83 into main Jan 26, 2026
11 checks passed
@kalbasit kalbasit deleted the 01-26-fix_cleanup_legacy_narinfo_in_putnarinfo_to_avoid_race_condition branch January 26, 2026 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants