Repository navigation
Conversation
This commit fixes issue #660 where multiple ncps instances fail to serve the same NAR file concurrently when one instance is still downloading it from upstream. Problem: When running multiple ncps servers in HA mode with shared storage (S3) and database (PostgreSQL), concurrent requests for the same NAR would fail with "failed to acquire download lock" errors. Only the first instance that acquired the lock could serve the NAR, while other instances would return errors instead of waiting for the download to complete and serving from shared storage. This was a regression between release-0.8 and HEAD, breaking the ability to horizontally scale ncps servers. Solution: Modified the download coordination logic to allow instances that fail to acquire the download lock to poll the shared storage and serve the NAR once another instance completes the download. This ensures all instances can successfully serve concurrent requests even during initial download. Testing: Added testDistributedLargeNARConcurrentDownload test that simulates the exact failure scenario: 3 cache instances requesting the same 12MB NAR concurrently while one is downloading. The test verifies all instances successfully serve the NAR without lock acquisition errors. Also includes minor code quality improvements: - Switched to crypto/rand for secure test data generation - Improved error messages with wrapped static errors - Added testdata.GenerateEntry() helper for custom NAR generation Part of #322
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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 addresses a critical regression in distributed cache setups where concurrent requests for the same NAR file would fail if multiple instances attempted to download it simultaneously. The core change introduces a robust coordination mechanism, allowing instances that initially fail to acquire a download lock to intelligently wait and serve the NAR once another instance completes the download. This restores the ability to horizontally scale cache servers effectively, ensuring high availability and consistent service delivery even under heavy concurrent load. Highlights
Changelog
Activity
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.
Code Review
This pull request provides a solid fix for the concurrent NAR streaming failures in a distributed setup. The introduction of a polling mechanism in coordinateDownload for instances that fail to acquire a download lock is a robust solution. The new test case, testDistributedLargeNARConcurrentDownload, is comprehensive and effectively validates the fix. I also appreciate the refactoring to use serveNarFromStorageViaPipe, which improves the resilience of NAR serving. The code is well-written and the changes are clear. I have one suggestion to enhance configurability.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #742 +/- ##
=======================================
Coverage 85.41% 85.41%
=======================================
Files 2 2
Lines 480 480
=======================================
Hits 410 410
Misses 65 65
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|

This commit fixes issue #660 where multiple ncps instances fail to serve
the same NAR file concurrently when one instance is still downloading it
from upstream.
Problem:
When running multiple ncps servers in HA mode with shared storage (S3)
and database (PostgreSQL), concurrent requests for the same NAR would
fail with "failed to acquire download lock" errors. Only the first
instance that acquired the lock could serve the NAR, while other
instances would return errors instead of waiting for the download to
complete and serving from shared storage.
This was a regression between release-0.8 and HEAD, breaking the ability
to horizontally scale ncps servers.
Solution:
Modified the download coordination logic to allow instances that fail to
acquire the download lock to poll the shared storage and serve the NAR
once another instance completes the download. This ensures all instances
can successfully serve concurrent requests even during initial download.
Testing:
Added testDistributedLargeNARConcurrentDownload test that simulates the
exact failure scenario: 3 cache instances requesting the same 12MB NAR
concurrently while one is downloading. The test verifies all instances
successfully serve the NAR without lock acquisition errors.
Also includes minor code quality improvements:
Part of #322