From f1fa9332ac704aed14b5c1460431bac953f27b85 Mon Sep 17 00:00:00 2001 From: Bagas Date: Sun, 19 Jul 2026 11:53:14 +0700 Subject: [PATCH] fix(registry): data race registry update (#156) Concurrent map read and map write crashing the whole server Bug fixes: - Fix data race in registry.Update Reviewed-on: https://git.fossy.my.id/bagas/tunnel-please/pulls/156 Co-authored-by: Bagas Co-committed-by: Bagas --- internal/registry/registry.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/registry/registry.go b/internal/registry/registry.go index a4f64a8..e911a8a 100644 --- a/internal/registry/registry.go +++ b/internal/registry/registry.go @@ -94,13 +94,13 @@ func (r *registry) Update(user string, oldKey, newKey Key) error { return ErrInvalidSlug } + r.mu.Lock() + defer r.mu.Unlock() + if _, exists := r.slugIndex[newKey]; exists && newKey != oldKey { return ErrSlugInUse } - r.mu.Lock() - defer r.mu.Unlock() - client, ok := r.byUser[user][oldKey] if !ok { return ErrSessionNotFound