[#325] Fix mutex usage in controller

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
pull/330/head
Denis Kirillov 2024-02-29 17:20:00 +03:00 committed by Alexey Vanin
parent 623001c403
commit 81b44ab3d3
1 changed files with 3 additions and 2 deletions

View File

@ -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)