Skip to content

Commit

Permalink
adds lock to message handler
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Nov 14, 2024
1 parent 26d07d7 commit 4431a6a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/mqtt/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"strings"
"sync"

paho "github.com/eclipse/paho.mqtt.golang"
"github.com/zmap/zgrab2"
Expand Down Expand Up @@ -112,10 +113,17 @@ func (s *scan) makeMessageHandler() func(c paho.Client, m paho.Message) {
return false
}

var mu sync.Mutex
var handler = func(c paho.Client, m paho.Message) {
mu.Lock()
defer mu.Unlock()

topic := m.Topic()
if isFull(topic) {
c.Unsubscribe(topic)
if t := c.Unsubscribe(topic); t.Wait() && t.Error() != nil {
// ignore
return
}
return
}

Expand Down

0 comments on commit 4431a6a

Please sign in to comment.