Skip to content

Commit bd40a3b

Browse files
committed
Mutex when initializing connection
1 parent 5bda38e commit bd40a3b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

extension/amqp/publisher.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package amqp
33
import (
44
"context"
55
"io"
6+
"sync"
67

78
"github.com/hellofresh/goengine"
89
"github.com/hellofresh/goengine/driver/sql"
@@ -20,6 +21,8 @@ type NotificationPublisher struct {
2021

2122
connection io.Closer
2223
channel NotificationChannel
24+
25+
mux sync.Mutex
2326
}
2427

2528
// NewNotificationPublisher returns an instance of NotificationPublisher
@@ -58,12 +61,14 @@ func (p *NotificationPublisher) Publish(ctx context.Context, notification *sql.P
5861
}
5962

6063
for {
64+
p.mux.Lock()
6165
if p.connection == nil {
6266
p.connection, p.channel, err = setup(p.amqpDSN, p.queue)
6367
if err != nil {
6468
return err
6569
}
6670
}
71+
p.mux.Unlock()
6772

6873
err = p.channel.Publish("", p.queue, true, false, amqp.Publishing{
6974
Body: msgBody,

0 commit comments

Comments
 (0)