Skip to content

Commit

Permalink
Don't send on unbuffered channel while holding a lock
Browse files Browse the repository at this point in the history
Longhorn 7919

Signed-off-by: Eric Weber <eric.weber@suse.com>
  • Loading branch information
ejweber authored and PhanLe1010 committed Feb 15, 2024
1 parent 1915645 commit ecd20d6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/process/process_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,19 @@ func (pm *Manager) checkMountPointStatusForEngine() {
if err != nil {
logrus.WithError(err).Warn("Failed to get all volume mount points")
}

pm.lock.RLock()
defer pm.lock.RUnlock()

processToUpdate := pm.getProcessToUpdateConditions(volumeMountPointMap)
for _, p := range processToUpdate {
// Locking is handled inside getProcessesToUpdateConditions.
processesToUpdate := pm.getProcessesToUpdateConditions(volumeMountPointMap)
for _, p := range processesToUpdate {
p.UpdateCh <- p
}
}

func (pm *Manager) getProcessToUpdateConditions(volumeMountPointMap map[string]mount.MountPoint) []*Process {
var processToUpdate []*Process
func (pm *Manager) getProcessesToUpdateConditions(volumeMountPointMap map[string]mount.MountPoint) []*Process {
var processesToUpdate []*Process

pm.lock.RLock()
defer pm.lock.RUnlock()

for _, p := range pm.processes {
p.lock.Lock()
if isEngineProcess(p) && p.State == StateRunning {
Expand All @@ -161,12 +162,12 @@ func (pm *Manager) getProcessToUpdateConditions(volumeMountPointMap map[string]m

if mp, exists := volumeMountPointMap[volumeNameSHAStr]; exists {
p.Conditions[types.EngineConditionFilesystemReadOnly] = util.IsMountPointReadOnly(mp)
processToUpdate = append(processToUpdate, p)
processesToUpdate = append(processesToUpdate, p)
}
}
p.lock.Unlock()
}
return processToUpdate
return processesToUpdate
}

func isEngineProcess(p *Process) bool {
Expand Down

0 comments on commit ecd20d6

Please sign in to comment.