Skip to content

Commit f5e434a

Browse files
kimtoresechmann
andcommitted
device-agent: status channels are now non-blocking, to avoid async bugs in systray
co-authored-by: Vegar Sechmann Molvig <[email protected]>
1 parent e29d687 commit f5e434a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/device-agent/deviceagent.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe
4444

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

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

5050
das.lock.Lock()
@@ -57,8 +57,8 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe
5757
das.log.Debugf("grpc: keepalive not requested, tearing down connections...")
5858
das.sendEvent(statemachine.EventDisconnect)
5959
}
60-
das.lock.Lock()
6160
close(agentStatusChan)
61+
das.lock.Lock()
6262
delete(das.statusChannels, id)
6363
das.lock.Unlock()
6464
}()
@@ -85,7 +85,11 @@ func (das *DeviceAgentServer) UpdateAgentStatus(status *pb.AgentStatus) {
8585

8686
das.lock.Lock()
8787
for _, c := range das.statusChannels {
88-
c <- status
88+
select {
89+
case c <- status:
90+
default:
91+
das.log.Errorf("BUG: update agent status: channel is full")
92+
}
8993
}
9094
das.lock.Unlock()
9195
}

0 commit comments

Comments
 (0)