From 6c85b6ca46e647ad8f98e8ca2cc364af11a03c33 Mon Sep 17 00:00:00 2001 From: Eric Weber Date: Tue, 13 Feb 2024 13:19:56 -0600 Subject: [PATCH] Don't send on unbuffered channel while holding a lock Longhorn 7919 Signed-off-by: Eric Weber (cherry picked from commit ecd20d67b88bf03412e465ba694c272102484063) --- pkg/process/process_manager.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkg/process/process_manager.go b/pkg/process/process_manager.go index 8c8e4c412..63d60eca2 100644 --- a/pkg/process/process_manager.go +++ b/pkg/process/process_manager.go @@ -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 { @@ -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 {