Skip to content

fix: atomic config swap — no panic, router/middleware always consistent - #8

Open
notr3kt wants to merge 1 commit into
jahmeergnlt:mainfrom
notr3kt:fix/atomic-config-swap-consistency
Open

fix: atomic config swap — no panic, router/middleware always consistent#8
notr3kt wants to merge 1 commit into
jahmeergnlt:mainfrom
notr3kt:fix/atomic-config-swap-consistency

Conversation

@notr3kt

@notr3kt notr3kt commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Fixes #1.

Configuration reloads from concurrent providers could:

  1. Panic on first swap (atomic.Value type mismatch: HandlerFunc*ServeMux)
  2. Risk stale / partial handler publish if rebuild and store were not a single consistent snapshot

Fix

  • handlerHolder wrapper so atomic.Value always stores one concrete type
  • Build complete mux from one config snapshot, then publish under mutex + single atomic store
  • Drain burst updates → apply latest only (serialized watcher)
  • GetConfig() returns deep copies

Tests

go test ./... -race -count=3
  • TestFirstConfigSwapDoesNotPanic
  • TestConfigAndHandlerStayConsistent (2000 reqs under dual providers)
  • TestGetConfigDeepCopy

Claim

/claim #1

- Store handlers in a stable handlerHolder so atomic.Value never panics
  when swapping HandlerFunc -> ServeMux on first reload
- Rebuild full mux from one config snapshot, then publish under lock
- Collapse concurrent provider bursts to latest config (no partial merge)
- Deep-copy GetConfig() so API readers cannot race writers
- Add race-detector tests for first-swap panic and body/header consistency
- Add CI with go test -race

Closes jahmeergnlt#1
@opirebot

opirebot Bot commented Jul 30, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.
Make sure your payment account is ready to receive the payment for your hard work 💪

@notr3kt

notr3kt commented Jul 30, 2026

Copy link
Copy Markdown
Author

Friendly bump for review when you have a moment.

  • go test ./... -race -count=3 green locally
  • Fixes atomic.Value panic + consistent router/middleware snapshot publish
  • Opire claim already registered for @notr3kt

Happy to iterate on any feedback.

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.

🎯 Fix Race Condition Causing Stale Middleware Chain During Concurrent Provider Updates

1 participant