fix(engine): avoid deadlock when stopping engine during debug bundle

This commit is contained in:
aliamerj
2025-09-16 21:06:54 +03:00
parent 9d5694ff4c
commit 889c3c8f8d
+10 -6
View File
@@ -927,12 +927,16 @@ func (e *Engine) receiveJobEvents() {
} }
func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobResponse_Bundle, error) { func (e *Engine) handleBundle(params *mgmProto.BundleParameters) (*mgmProto.JobResponse_Bundle, error) {
// todo: @Vic, do we need to latest sync response all the time here or could it be nil in the debug bundle? // Access sync response directly without calling exported method to avoid deadlock
// todo: e.GetLatestSyncResponse() is exported and has been protected by a mutex. If you will use handleBundle in // This is safe because we're in a goroutine that doesn't hold the syncMsgMux
// also protected context then will be deadlock var syncResponse *mgmProto.SyncResponse
syncResponse, err := e.GetLatestSyncResponse() if e.persistSyncResponse && e.latestSyncResponse != nil {
if err != nil { log.Debugf("Retrieving latest sync response with size %d bytes", proto.Size(e.latestSyncResponse))
return nil, fmt.Errorf("get latest sync response: %w", err) if sr, ok := proto.Clone(e.latestSyncResponse).(*mgmProto.SyncResponse); ok {
syncResponse = sr
} else {
return nil, fmt.Errorf("failed to clone sync response")
}
} }
if syncResponse == nil { if syncResponse == nil {