Refactor SetStatus method to capture onStatusChange callback reference before unlocking mutex

This commit is contained in:
2025-08-28 18:59:26 +02:00
parent 0b058237fe
commit 227ca7927a

View File

@@ -30,10 +30,12 @@ func (p *Process) SetStatus(status InstanceStatus) {
p.mu.Lock()
oldStatus := p.Status
p.Status = status
callback := p.onStatusChange // Capture callback reference
p.mu.Unlock()
if p.onStatusChange != nil {
p.onStatusChange(oldStatus, status)
// Call callback outside the lock to prevent deadlocks
if callback != nil {
callback(oldStatus, status)
}
}