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)