Skip to content

Commit

Permalink
Ensure the lock is in place before creating queued disabled events
Browse files Browse the repository at this point in the history
Signed-off-by: mprahl <mprahl@users.noreply.github.com>
  • Loading branch information
mprahl authored and openshift-merge-bot[bot] committed Mar 21, 2024
1 parent 5e2d6c5 commit f96737a
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions controllers/complianceeventsapi/complianceeventsapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,25 @@ func MonitorDatabaseConnection(
continue
}

complianceServerCtx.Lock.RUnlock()

if complianceServerCtx.needsMigration {
// Upgrade to a write lock to migrate the database.
complianceServerCtx.Lock.RUnlock()
complianceServerCtx.Lock.Lock()
err := complianceServerCtx.MigrateDB(ctx, client, controllerNamespace)
complianceServerCtx.Lock.Unlock()

if err != nil {
continue
}

// Reinitate the read lock and ensure the DB is still defined after obtaining the lock.
complianceServerCtx.Lock.RLock()

if complianceServerCtx.DB == nil {
complianceServerCtx.Lock.RUnlock()

continue
}
}

log.V(3).Info(
Expand Down Expand Up @@ -336,6 +345,8 @@ func MonitorDatabaseConnection(
if shutdown {
log.Info("The queue was shutdown. Exiting MonitorDatabaseConnection.")

complianceServerCtx.Lock.RUnlock()

return
}
}
Expand All @@ -346,6 +357,8 @@ func MonitorDatabaseConnection(
"queueLength", complianceServerCtx.Queue.Len(),
)
}

complianceServerCtx.Lock.RUnlock()
}
}

Expand Down

0 comments on commit f96737a

Please sign in to comment.