[#325] Fix mutex usage in controller

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2024-02-29 17:20:00 +03:00 committed by Alexey Vanin
parent 623001c403
commit 81b44ab3d3

View file

@ -136,10 +136,11 @@ func (c *Controller) Subscribe(_ context.Context, topic string, handler layer.Ms
ch := make(chan *nats.Msg, 1) ch := make(chan *nats.Msg, 1)
c.mu.RLock() 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) return fmt.Errorf("already subscribed to topic '%s'", topic)
} }
c.mu.RUnlock()
if _, err := c.jsClient.AddStream(&nats.StreamConfig{Name: topic}); err != nil { if _, err := c.jsClient.AddStream(&nats.StreamConfig{Name: topic}); err != nil {
return fmt.Errorf("add stream: %w", err) return fmt.Errorf("add stream: %w", err)