jmsperu opened a new pull request, #12680:
URL: https://github.com/apache/cloudstack/pull/12680

   ## Description
   
   `NASBackupProvider.syncBackupStorageStats()` crashes with a 
`NullPointerException` when 
`ResourceManager.findOneRandomRunningHostByHypervisor()` returns `null`. This 
happens when no KVM host in the zone has `status=Up` at the moment the 
`BackupSyncTask` runs (e.g., during management server startup, brief agent 
disconnections, or host state transitions).
   
   The NPE kills the entire `BackupSyncTask` background job every sync interval 
(default 300s), flooding the management server log with stack traces and 
preventing backup storage stats from being updated.
   
   The same pattern exists in `deleteBackup()` where `host` can be null when 
the VM is removed and no running KVM host is available.
   
   ### Stack Trace
   
   ```
   ERROR [o.a.c.b.B.BackupSyncTask] Error trying to run backup-sync background 
task due to:
   [Cannot invoke "com.cloud.host.Host.getId()" because "host" is null].
   java.lang.NullPointerException: Cannot invoke "com.cloud.host.Host.getId()" 
because "host" is null
       at 
org.apache.cloudstack.backup.NASBackupProvider.syncBackupStorageStats(NASBackupProvider.java:544)
       at 
org.apache.cloudstack.backup.BackupManagerImpl$BackupSyncTask.runInContext(BackupManagerImpl.java:1947)
   ```
   
   ## Changes
   
   - `syncBackupStorageStats()`: Add early return with warning log when no 
running KVM host is found
   - `deleteBackup()`: Add null check with descriptive `CloudRuntimeException`
   
   ## How Has This Been Tested
   
   Tested on a production CloudStack 4.22.0.0 deployment with 3 KVM hosts and 
NAS (NFS) backup provider. Before the fix, the NPE fired every 5 minutes after 
management server restart. After applying the patch, the `BackupSyncTask` runs 
cleanly — logging a warning during startup and resuming normally once hosts 
reconnect.
   
   ## Types of changes
   
   - [x] Bug fix (non-breaking change which fixes an issue)
   
   ## Screenshot / Video (if applicable)
   
   Before (every 5 minutes):
   ```
   ERROR [o.a.c.b.B.BackupSyncTask] Error trying to run backup-sync background 
task due to:
   [Cannot invoke "com.cloud.host.Host.getId()" because "host" is null]
   ```
   
   After:
   ```
   WARN  [o.a.c.b.NASBackupProvider] Unable to find a running KVM host in zone 
1 to sync backup storage stats
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to