Repository navigation
cache: create the cache package auto-generating secretKey if not found - #2
Merged
Merged
Conversation
kalbasit
added a commit
that referenced
this pull request
Dec 1, 2024
* main: cache: create the cache package auto-generating secretKey if not found (#2)
3 tasks done
kalbasit
added a commit
that referenced
this pull request
May 24, 2026
## Summary Three pre-existing `pkg/cache` flakes from #1247 share one root cause: assertions that race against absolute wall-clock time and break under CI load even when the production code is correct. Surfaced repeatedly during the lean-flake-check measurement runs in #1249 (which sits stacked on top of this branch). All three fixes are **test-only**. No production code is touched. ## What changed | Flake (from #1247) | Test | Before | After | | --- | --- | --- | --- | | #5 | `TestCDCBackends/{SQLite,MySQL}/first_pull_completes_before_CDC_chunking_finishes` | `assert.Less(elapsed, 500ms)` racing the slow chunker | Happens-before check: `select { case <-chunkingStarted: t.Fatal(…) }` after `io.ReadAll`. `slowChunker` grew an optional `started chan struct{}` closed when its delay expires. Delay bumped 500 ms → 10 s (only matters under regression). | | #1 | `TestCacheBackends/MySQL/PutNarInfoDeadlock` | `context.WithTimeout(2s)` then `assert.NoError`. Could not distinguish "deadlock" from "MariaDB slow." | Timeout bumped 2 s → 60 s. A real deadlock still fails fast; non-deadlocked slow path now passes. | | #2 | Six instances of `assert.WithinDuration(CreatedAt, LastAccessedAt, 2s)` across `TestCacheBackends` | 2 s tolerance was tight enough that two CLOSE-TO-NOW() timestamps from different SQL operations under MariaDB load could fall outside it (observed -3 s spread). | Tolerance bumped 2 s → 30 s. Still tight enough to catch a genuinely broken "set both timestamps at row creation" semantic. | ## Why "test-only" and not "fix the production bug" These three are *measurement bugs*: the assertions encode an assumption ("operation X completes within Y milliseconds") that's an artifact of the dev host's speed, not a property the codebase ever promised. The behavior the tests *want* to verify (no deadlock, timestamps set close together at creation, GetNar doesn't block on chunking) is still being verified — the encoding is just no longer wall-clock-dependent. Flakes #3 and #4 from #1247 are NOT addressed here because they are not the same shape: - **#3** (`ConcurrentDownloadCancelOneClientOthersContinue`, 20-min hang) is a real hang in `io.ReadAll(readerB)` or `wg.Wait()` after all the existing 5–10 s guards have passed — almost certainly a production-code bug in the shared-reader-fanout path. Filed as **#1252** for separate investigation. - **#4** (`GetNarInfoConcurrentPutNarInfoDuringMigration`) exercises the same concurrent-migration-vs-PutNarInfo window that the next test (`testGetNarInfoMultipleConcurrentPutsDuringMigration`) explicitly `t.Skip`s with `"blocked on pgx transaction-abort cascade in PutNarInfo re-fetch path"`. That tracked production bug is the actual root cause; this test exercising it less reliably isn't a separate issue. ## Stack This PR is stacked under #1249 (`improve-flake-check-time`); landing this first should unblock #1249's CI by eliminating three of the five flakes that were causing intermittent reds. ``` main → fix-cache-test-timing-assertions (this PR, #1253) → improve-flake-check-time (#1249) ``` ## Test plan - [x] `nix develop -- go test -race -count=1 -run "TestCDCBackends/SQLite/first_pull_completes_before_CDC_chunking_finishes" ./pkg/cache/` passes locally. - [x] `nix develop -- go test -race -count=1 -run "TestCacheBackends/SQLite/(PutNarInfoDeadlock|GetNarInfo/narinfo_exists_upstream/nar_does_exist)" ./pkg/cache/` passes locally. - [x] `golangci-lint run` clean (run inside `nix develop` so the toolchain resolves). --------- Co-authored-by: Claude Opus 4.7 <[email protected]>
5 of 6 tasks
4 tasks done
kalbasit
added a commit
that referenced
this pull request
Jun 10, 2026
## Summary A **second, distinct** dev-harness bug from the chunked-body fix in #1390 (which is necessary and stays). After #1390, `nix copy` of a large closure (e.g. a ~9.35 GB `nixos-system`) to the `:8500` HA proxy **still** intermittently fails with `curl error 56: Connection reset by peer`, aborting the whole copy on the first reset. **Root cause:** the proxy's `ProxyHandler` left `protocol_version` at the stdlib `BaseHTTPRequestHandler` default of **HTTP/1.0**, so it force-closed every client connection after one request. `nix copy` pushes hundreds of objects over a small pool of HTTP/1.1 keep-alive connections; because the proxy refused keep-alive, nix was forced to open a brand-new TCP connection per object — thousands for a multi-GB closure. Under that churn (amplified by the default listen backlog of 5 and a ~1 s-per-PUT stall from unanswered `Expect: 100-continue`), the accept loop stalls and intermittently nix's upload connection is reset **before the proxy ever handles it** (`curl error 56`). **Reproduced & fix-validated** on a clean isolated ncps behind the real proxy: the unpatched proxy dies at PUT #2; the patched proxy completes **3,488 PUTs with 0 resets**. `curl -v` confirms `HTTP/1.1 200` + "Connection left intact" (reuse). ## What changed (`dev-scripts/run.py` proxy only; ncps unchanged) - `ProxyHandler.protocol_version = "HTTP/1.1"` — persistent, reused client connections; also makes `BaseHTTPRequestHandler` auto-answer `Expect: 100-continue`, removing the per-PUT stall. - Response framing for safe reuse: preserve `Content-Length`; treat `204`/`304`/`HEAD`/`1xx` as bodiless; send `Connection: close` when the body length is unknown (e.g. backend chunked, stripped as hop-by-hop) so the client reads to EOF instead of mis-framing the next response. - Raise the listener backlog (`request_queue_size`) above the stdlib default of 5, set before the socket is activated. - All #1390 hardening preserved (chunked request-body forwarding, RFC 7230 §3.3.3, bounded `_fail` drain, error logging). ## Test plan - [x] `task fmt` (0 changed), `task lint` (0 issues), `task test` (all Go packages ok) - [x] New keep-alive / framing / `Expect: 100-continue` regression tests drive the real `run.py` proxy via `NCPS_RUN_PY`; confirmed RED on HTTP/1.0, GREEN after the fix - [x] `e2e-harness-unit` nix check green (52 passed; +4 new tests) - [x] End-to-end: full `nix copy` of the 9.35 GB closure through the patched proxy — 3,488 PUTs, 0 resets --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Create the cache package, and have auto-load or auto-generate the secret key if it does not exist.