Skip to content

Commit

Permalink
Merge pull request #64 from reubenmiller/fix-notification2-concurrent…
Browse files Browse the repository at this point in the history
…-write

fix(notifications2): prevent concurrent socket writes by using a single send channel
  • Loading branch information
reubenmiller authored Jun 1, 2024
2 parents 6ec4ff7 + d77c30d commit 735b7db
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/c8y/notification2/notification2.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ func (c *Notification2Client) Register(pattern string, out chan<- Message) {

func (c *Notification2Client) SendMessageAck(messageIdentifier []byte) error {
Logger.Debugf("Sending message ack: %s", messageIdentifier)
c.ws.SetWriteDeadline(time.Now().Add(c.ConnectionOptions.GetWriteDuration()))
return c.ws.WriteMessage(websocket.TextMessage, messageIdentifier)
c.send <- messageIdentifier
return nil
}

func (c *Notification2Client) worker() error {
Expand Down Expand Up @@ -437,6 +437,6 @@ func (c *Notification2Client) worker() error {
// Unsubscribe unsubscribe to a given pattern
func (c *Notification2Client) Unsubscribe() error {
Logger.Info("unsubscribing")
c.ws.SetWriteDeadline(time.Now().Add(c.ConnectionOptions.GetWriteDuration()))
return c.ws.WriteMessage(websocket.TextMessage, []byte("unsubscribe_subscriber"))
c.send <- []byte("unsubscribe_subscriber")
return nil
}

0 comments on commit 735b7db

Please sign in to comment.