Repository navigation
fix: fail-fast boot validation for storage tmp directory [backport #1086] - #1087
Conversation
This adds a writability check for the store/tmp directory in setupDirs() to ensure the server fails fast at boot time if the tmp directory is not writable. Previously, the server would fail silently when downloading NARs or during background migration to chunks, causing database records to exist without corresponding files in storage. The new validation creates a temp file in the tmp directory and cleans it up immediately. (cherry picked from commit 06337a9)
Summary of ChangesHello, 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 enhances the system's robustness by introducing early validation for temporary storage directories. By performing writability checks at boot time, the system can now fail fast if critical temporary directories are not accessible, preventing scenarios where database records exist without corresponding files in storage due to silent failures during operations like NAR downloads or background migrations. This change improves data integrity and simplifies debugging by making issues apparent immediately upon startup. Highlights
Changelog
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
|
|
Related Documentation 2 document(s) may need updating based on files changed in this PR: kalbasit's Space Cache and Storage Configuration FlagsView Suggested Changes@@ -89,7 +89,14 @@
temp-path: "/var/lib/ncps/temp"
```
-**Note:** On some systems, the default `/tmp` directory may have limited space or be stored in memory (e.g., tmpfs on NixOS). In these cases, setting a custom temporary directory with sufficient disk space is recommended.
+**Boot-Time Validation:** The server performs a writability check on the temporary directory at boot time. If the directory is not writable, the server will fail to start with an error message. This validation prevents silent failures that previously occurred during NAR downloads or background migrations to chunks.
+
+**Error Example:**
+```
+error setting cache temp dir: error verifying tmp directory is writable: ...
+```
+
+**Note:** On some systems, the default `/tmp` directory may have limited space or be stored in memory (e.g., tmpfs on NixOS). In these cases, setting a custom temporary directory with sufficient disk space is recommended. Ensure the configured temporary directory has write permissions before starting the server.
### S3 Storage
Configure S3 storage using flags prefixed with `--cache-storage-s3-` (CLI) or under `cache.storage.s3` (YAML). Required options include the bucket name, endpoint (must include scheme, e.g., `https://s3.amazonaws.com` or `http://localhost:9000`), access key ID, and secret access key. The `force-path-style` option is required for MinIO and other S3-compatible services, and optional for AWS S3.NAR File Download and StreamingView Suggested Changes@@ -178,7 +178,7 @@
When CDC is enabled and decompression is performed, the cleanup goroutine removes the uncompressed temporary file (`assetPath`) after all readers finish. The `compressedAssetPath` field is kept in the `downloadState` struct for backward compatibility but remains empty in the CDC pipeline since PR #1071 replaced the compressed temp file with an `io.Pipe`. This ensures that no temporary files persist after the NAR is stored.
-On startup, ncps cleans up any leftover temporary files from previous runs by removing the temp directory and recreating it [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/storage/local/local.go#L305-L459).
+On startup, ncps cleans up any leftover temporary files from previous runs by removing the temp directory and recreating it. The server validates that the temp directory is writable during boot and will fail immediately with an error if it cannot write to the directory. This boot-time validation ensures proper write permissions are a prerequisite for server startup, catching configuration issues early rather than encountering silent failures during NAR downloads or background migrations. The validation is performed by the `SetTempDir` function (which now returns an error if the directory is not writable) and the storage backend's `setupDirs` function, both of which use `helper.EnsureDirWritable` to create a temporary test file and verify write permissions [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/pkg/storage/local/local.go#L305-L459).
### Configuration of Temporary Download Paths
The temporary directory for downloads is configurable via the `--cache-temp-path` flag or the `CACHE_TEMP_PATH` environment variable. By default, ncps uses the OS temporary directory. For local storage backends, a `tmp` subdirectory under the store path is used [source](https://github.com/kalbasit/ncps/blob/b7653d4303670bb88fd34b8bf82ed3aade09885d/cmd/serve.go#L176-L529).Note: You must be authenticated to accept/decline updates. |
There was a problem hiding this comment.
Code Review
This pull request introduces a fail-fast validation mechanism by checking for writability of temporary directories at boot time. This is achieved by adding a new helper function EnsureDirWritable that creates and then removes a temporary file. This function is now used when setting the cache's temporary directory and when setting up the local storage directories. The changes are logical, well-implemented, and include corresponding tests for the new behavior. The error handling has been updated correctly where the new validation is used. Overall, this is a solid improvement for robustness.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-0.9 #1087 +/- ##
===========================================
Coverage 5.04% 5.04%
===========================================
Files 6 6
Lines 436 436
===========================================
Hits 22 22
Misses 410 410
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Bot-based backport to
release-0.9, triggered by a label in #1086.This adds a writability check for the store/tmp directory in setupDirs()
to ensure the server fails fast at boot time if the tmp directory is not
writable. Previously, the server would fail silently when downloading
NARs or during background migration to chunks, causing database records
to exist without corresponding files in storage. The new validation
creates a temp file in the tmp directory and cleans it up immediately.