Repository navigation
fix: fail-fast boot validation for storage tmp directory - #1086
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
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 an early validation step during the boot process. It specifically checks the writability of the temporary storage directory, ensuring that critical file system permissions are correctly configured from the start. This proactive measure prevents silent failures and potential data corruption that could arise from an unwritable temporary directory, thereby improving overall system reliability and data consistency. 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
|
|
Documentation Updates 2 document(s) were updated by changes in this PR: Cache and Storage Configuration FlagsView Changes@@ -88,6 +88,8 @@
cache:
temp-path: "/var/lib/ncps/temp"
```
+
+**Boot-Time Validation:** The server validates that the temporary directory is writable during startup by creating and removing a test file. If the directory is not writable, the server will fail to start immediately with an error. This fail-fast behavior ensures that configuration issues are caught at boot time rather than during runtime operations such as NAR downloads or background chunk migrations.
**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.
NAR File Download and StreamingView 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 also validates that the temporary directory is writable during startup by creating and removing a test file. If the temporary directory is not writable, the server will fail to start immediately with an error, preventing silent failures that could occur later during NAR download operations. This boot-time validation ensures configuration issues are detected early, before the server begins accepting requests [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). |
There was a problem hiding this comment.
Code Review
This pull request adds a useful writability check for the temporary directory during startup, which helps the server fail fast with a clear error message. The suggestion to make the cleanup logic more robust by handling potential errors, especially from Close(), is valid and aligns with the goal of failing fast on any issue, as such errors are not considered benign in this context. This comment is kept as it does not contradict any existing rules.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1086 +/- ##
=====================================
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:
|
3202c7a to
cfdfc24
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable fail-fast validation by checking if the temporary directory is writable at boot time. This is a good improvement to prevent silent failures later on. The implementation is correct, and tests have been added to cover the new logic.
My main feedback is regarding code duplication. The writability check logic has been added in two different places (pkg/cache/cache.go and pkg/storage/local/local.go). I've left a comment suggesting to extract this into a shared helper function to improve maintainability.
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.
cfdfc24 to
eb9c55a
Compare
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)
|
Successfully created backport PR for |
] (#1087) 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.
## Summary The `[Unreleased]` section was populated in #1309 but skewed toward the recent CDC-drain, in-flight-staging, and Ent-migration work, omitting several user-facing features and fixes that also landed since v0.9.4. This backfills the missing notable changes, each cross-referenced by PR. **Added** - `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999, #1000, #1004, #1006, #1176) - Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`, `GET /pins` (#1108) - pprof server via `--pprof-addr` (#1063) - CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` + recovery cron (#1082, #1083, #1089, #1096) - Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume / `volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012) - Startup storage reporting + deprecated-narinfo warning (#959, #961) - `docker-dev` image (#1097) **Fixed** - `store/tmp` no longer wiped on startup (#1313) - `nix-hash` NAR verification (#1101) - Prometheus counters primed at startup (#1337, #1343) - 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer 500 (#1318), fail-fast tmp validation (#1086) - Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342, #1331, #1347) **Changed** - CDC config now persisted in the DB config table (#971) Dependency bumps, CI/test-only changes, and the internal Ent-conversion PRs are intentionally excluded; the existing Ent-migration entry already covers that work. ## Test plan - [x] `nix fmt` reports no changes (docs-only edit) - [x] CHANGELOG section structure intact (Added/Fixed/Changed/Removed/Migration/CI)
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.