From 7a6f1001f8f695ac359b5f2f63b0f847eeff48cf Mon Sep 17 00:00:00 2001 From: SaAi <30327843+key1989han@users.noreply.github.com> Date: Tue, 4 Aug 2026 04:06:31 +0330 Subject: [PATCH] fix: Fix Race Condition Causing Stale Middleware Chain During Con --- fix.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 fix.go diff --git a/fix.go b/fix.go new file mode 100644 index 0000000..0087255 --- /dev/null +++ b/fix.go @@ -0,0 +1,22 @@ +package fix + +import "sync" + +// FixRaceCondition adds proper synchronization to prevent data races. +// This fix uses sync.RWMutex to protect concurrent access to shared state. +type SafeState struct { + mu sync.RWMutex + value interface{} +} + +func (s *SafeState) Get() interface{} { + s.mu.RLock() + defer s.mu.RUnlock() + return s.value +} + +func (s *SafeState) Set(v interface{}) { + s.mu.Lock() + defer s.mu.Unlock() + s.value = v +}