@@ -19,13 +19,14 @@ import (
19
19
20
20
type DeviceAgentServer struct {
21
21
pb.UnimplementedDeviceAgentServer
22
- lock sync.RWMutex
23
- statusChannels map [uuid.UUID ]chan * pb.AgentStatus
24
- Config * config.Config
25
- notifier notify.Notifier
26
- rc runtimeconfig.RuntimeConfig
27
- log * logrus.Entry
28
- sendEvent func (state.EventWithSpan )
22
+ Config * config.Config
23
+ notifier notify.Notifier
24
+ rc runtimeconfig.RuntimeConfig
25
+ log * logrus.Entry
26
+ sendEvent func (state.EventWithSpan )
27
+
28
+ statusChannelsLock sync.RWMutex
29
+ statusChannels map [uuid.UUID ]chan * pb.AgentStatus
29
30
30
31
AgentStatus * pb.AgentStatus
31
32
agentStatusLock sync.RWMutex
@@ -51,20 +52,20 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe
51
52
agentStatusChan <- das .AgentStatus
52
53
das .agentStatusLock .RUnlock ()
53
54
54
- das .lock .Lock ()
55
+ das .statusChannelsLock .Lock ()
55
56
das .statusChannels [id ] = agentStatusChan
56
- das .lock .Unlock ()
57
+ das .statusChannelsLock .Unlock ()
57
58
58
59
defer func () {
59
60
das .log .Debugf ("grpc: client connection with device helper closed" )
60
61
if ! request .GetKeepConnectionOnComplete () {
61
62
das .log .Debugf ("grpc: keepalive not requested, tearing down connections..." )
62
63
das .sendEvent (state .SpanEvent (statusServer .Context (), state .EventDisconnect ))
63
64
}
65
+ das .statusChannelsLock .Lock ()
64
66
close (agentStatusChan )
65
- das .lock .Lock ()
66
67
delete (das .statusChannels , id )
67
- das .lock .Unlock ()
68
+ das .statusChannelsLock .Unlock ()
68
69
}()
69
70
70
71
for {
@@ -89,15 +90,15 @@ func (das *DeviceAgentServer) UpdateAgentStatus(status *pb.AgentStatus) {
89
90
das .AgentStatus = status
90
91
das .agentStatusLock .Unlock ()
91
92
92
- das .lock .RLock ()
93
+ das .statusChannelsLock .RLock ()
93
94
for _ , c := range das .statusChannels {
94
95
select {
95
96
case c <- status :
96
97
default :
97
98
das .log .Errorf ("BUG: update agent status: channel is full" )
98
99
}
99
100
}
100
- das .lock .RUnlock ()
101
+ das .statusChannelsLock .RUnlock ()
101
102
}
102
103
103
104
func (das * DeviceAgentServer ) SetAgentConfiguration (ctx context.Context , req * pb.SetAgentConfigurationRequest ) (* pb.SetAgentConfigurationResponse , error ) {
0 commit comments