From 81b44ab3d391a74c4bd2b48bb1cf80083bade16f Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 29 Feb 2024 17:20:00 +0300 Subject: [PATCH] [#325] Fix mutex usage in controller Signed-off-by: Denis Kirillov --- api/notifications/controller.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/notifications/controller.go b/api/notifications/controller.go index 353ea84..1ce6919 100644 --- a/api/notifications/controller.go +++ b/api/notifications/controller.go @@ -136,10 +136,11 @@ func (c *Controller) Subscribe(_ context.Context, topic string, handler layer.Ms ch := make(chan *nats.Msg, 1) c.mu.RLock() - if _, ok := c.handlers[topic]; ok { + _, ok := c.handlers[topic] + c.mu.RUnlock() + if ok { return fmt.Errorf("already subscribed to topic '%s'", topic) } - c.mu.RUnlock() if _, err := c.jsClient.AddStream(&nats.StreamConfig{Name: topic}); err != nil { return fmt.Errorf("add stream: %w", err)