Skip to content

fix(di): scope config-derived resources to a configuration generation (A02) - #99

Merged
evg4b merged 1 commit into
mainfrom
fix/a02-generation-scoped-resources
Aug 30, 2026
Merged

fix(di): scope config-derived resources to a configuration generation (A02)#99
evg4b merged 1 commit into
mainfrom
fix/a02-generation-scoped-resources

Conversation

@evg4b

@evg4b evg4b commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Fixes review finding A02 — The DI container leaks a HAR writer per reload and permanently ignores cache-config changes.

The container held one append-only closer slice that was drained only at
process exit, so every config reload leaked a HAR writer plus its goroutine and
left stale writers racing to rewrite the same archive. The cache went the other
way: factory1 memoised the first instance and silently ignored the argument,
so cache-config changes never applied.

  • New di.Runtime owns everything derived from one UncorsConfig (routers,
    targets, HAR writers, the response cache) and releases it on Close.
  • Uncors builds the next generation before restarting, so a config that fails
    to build leaves the running proxy untouched, and closes the previous one only
    once the new one is live.
  • Shutdown/Close release the active generation, which flushes HAR writers.
  • cache-config is now genuinely hot-reloadable; the vestigial factory1 is
    gone.

Review

One commit, e2083d9. Step 2 of 33 in the review stack.

This PR targets fix/a01-request-tracker-non-blocking, the branch for the preceding finding, so that the diff shown here is exactly this one commit and nothing else. GitHub retargets it to main automatically once that base merges.

make check (gofmt, gofumpt, golangci-lint, unit tests with -race, dead-code analysis, build) and the
tagged integration suite pass at this commit.

@evg4b
evg4b force-pushed the fix/a02-generation-scoped-resources branch from e2083d9 to 525289a Compare August 30, 2026 16:21
@evg4b
evg4b changed the base branch from fix/a01-request-tracker-non-blocking to main August 30, 2026 16:21
… (A02)

The container held one append-only closer slice that was drained only at
process exit, so every config reload leaked a HAR writer plus its goroutine and
left stale writers racing to rewrite the same archive. The cache went the other
way: `factory1` memoised the first instance and silently ignored the argument,
so `cache-config` changes never applied.

- New `di.Runtime` owns everything derived from one `UncorsConfig` (routers,
  targets, HAR writers, the response cache) and releases it on `Close`.
- `Uncors` builds the next generation before restarting, so a config that fails
  to build leaves the running proxy untouched, and closes the previous one only
  once the new one is live.
- `Shutdown`/`Close` release the active generation, which flushes HAR writers.
- `cache-config` is now genuinely hot-reloadable; the vestigial `factory1` is
  gone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@evg4b
evg4b force-pushed the fix/a02-generation-scoped-resources branch from 525289a to 60c67df Compare August 30, 2026 16:29
@evg4b
evg4b marked this pull request as ready for review August 30, 2026 16:31
@evg4b
evg4b merged commit 2a39ea5 into main Aug 30, 2026
6 of 7 checks passed
@evg4b
evg4b deleted the fix/a02-generation-scoped-resources branch August 30, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant