Skip to content

Commit

Permalink
device-agent: status channels are now non-blocking, to avoid async bu…
Browse files Browse the repository at this point in the history
…gs in systray

co-authored-by: Vegar Sechmann Molvig <vegar.sechmann.molvig@nav.no>
  • Loading branch information
kimtore and sechmann committed Mar 8, 2024
1 parent e29d687 commit f5e434a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/device-agent/deviceagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe

das.log.Debug("grpc: client connection established to device helper")

agentStatusChan := make(chan *pb.AgentStatus, 1)
agentStatusChan := make(chan *pb.AgentStatus, 8)
agentStatusChan <- das.AgentStatus

das.lock.Lock()
Expand All @@ -57,8 +57,8 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe
das.log.Debugf("grpc: keepalive not requested, tearing down connections...")
das.sendEvent(statemachine.EventDisconnect)
}
das.lock.Lock()
close(agentStatusChan)
das.lock.Lock()
delete(das.statusChannels, id)
das.lock.Unlock()
}()
Expand All @@ -85,7 +85,11 @@ func (das *DeviceAgentServer) UpdateAgentStatus(status *pb.AgentStatus) {

das.lock.Lock()
for _, c := range das.statusChannels {
c <- status
select {
case c <- status:
default:
das.log.Errorf("BUG: update agent status: channel is full")
}
}
das.lock.Unlock()
}
Expand Down

0 comments on commit f5e434a

Please # to comment.