Skip to content

Commit 3cbbd47

Browse files
sechmannCopilot
andcommitted
fix: read status with lock
Co-authored-by: Copilot <[email protected]>
1 parent 73db91b commit 3cbbd47

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

internal/deviceagent/deviceagent.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ func (das *DeviceAgentServer) Status(request *pb.AgentStatusRequest, statusServe
6969

7070
defer func() {
7171
das.log.Debug("grpc: client connection with device helper closed")
72-
if !request.GetKeepConnectionOnComplete() || das.AgentStatus.GetConnectionState() != pb.AgentState_Connected {
72+
das.agentStatusLock.RLock()
73+
keepConnection := request.GetKeepConnectionOnComplete()
74+
connectionState := das.AgentStatus.GetConnectionState()
75+
das.agentStatusLock.RUnlock()
76+
if !keepConnection || connectionState != pb.AgentState_Connected {
7377
das.log.Debug("grpc: keepalive not requested, tearing down connections...")
7478
das.sendEvent(state.SpanEvent(statusServer.Context(), state.EventDisconnect))
7579
}

0 commit comments

Comments
 (0)