Skip to content

Commit

Permalink
improve debug logging, rw lock for notifier
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
  • Loading branch information
kradalby committed Sep 19, 2023
1 parent 3bef63b commit 217ccd6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions hscontrol/auth_noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func (ns *noiseServer) NoiseRegistrationHandler(

log.Trace().
Any("headers", req.Header).
Caller().
Msg("Headers")

body, _ := io.ReadAll(req.Body)
Expand Down
19 changes: 16 additions & 3 deletions hscontrol/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type Notifier struct {
l sync.Mutex
l sync.RWMutex
nodes map[string]chan<- types.StateUpdate
}

Expand All @@ -18,6 +18,9 @@ func NewNotifier() *Notifier {
}

func (n *Notifier) AddNode(machineKey string, c chan<- types.StateUpdate) {
log.Trace().Caller().Str("key", machineKey).Msg("acquiring lock to add node")
defer log.Trace().Caller().Str("key", machineKey).Msg("releasing lock to add node")

n.l.Lock()
defer n.l.Unlock()

Expand All @@ -34,6 +37,9 @@ func (n *Notifier) AddNode(machineKey string, c chan<- types.StateUpdate) {
}

func (n *Notifier) RemoveNode(machineKey string) {
log.Trace().Caller().Str("key", machineKey).Msg("acquiring lock to remove node")
defer log.Trace().Caller().Str("key", machineKey).Msg("releasing lock to remove node")

n.l.Lock()
defer n.l.Unlock()

Expand All @@ -54,14 +60,21 @@ func (n *Notifier) NotifyAll(update types.StateUpdate) {
}

func (n *Notifier) NotifyWithIgnore(update types.StateUpdate, ignore ...string) {
n.l.Lock()
defer n.l.Unlock()
log.Trace().Caller().Interface("type", update.Type).Msg("acquiring lock to notify")
defer log.Trace().
Caller().
Interface("type", update.Type).
Msg("releasing lock, finished notifing")

n.l.RLock()
defer n.l.RUnlock()

for key, c := range n.nodes {
if util.IsStringInSlice(ignore, key) {
continue
}

log.Trace().Caller().Str("machine", key).Strs("ignoring", ignore).Msg("sending update")
c <- update
}
}
1 change: 1 addition & 0 deletions hscontrol/poll_noise.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (ns *noiseServer) NoisePollNetMapHandler(

log.Trace().
Any("headers", req.Header).
Caller().
Msg("Headers")

body, _ := io.ReadAll(req.Body)
Expand Down

0 comments on commit 217ccd6

Please sign in to comment.