From 79e9bac556a9c8fd7f79c412eae2bdd657bb3603 Mon Sep 17 00:00:00 2001 From: Suresh Kumar Anaparti Date: Mon, 4 Aug 2025 16:16:31 +0530 Subject: [PATCH] Fix NPE during VM IP fetch for shared networks --- .../src/main/java/com/cloud/vm/UserVmManagerImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java index 91897c0977de..74a7cafa65fd 100644 --- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java @@ -672,7 +672,7 @@ public void setKubernetesServiceHelpers(final List kube "Wait Interval (in seconds) for shared network vm dhcp ip addr fetch for next iteration ", true); private static final ConfigKey VmIpFetchTrialMax = new ConfigKey("Advanced", Integer.class, "externaldhcp.vmip.max.retry", "10", - "The max number of retrieval times for shared entwork vm dhcp ip fetch, in case of failures", true); + "The max number of retrieval times for shared network vm dhcp ip fetch, in case of failures", true); private static final ConfigKey VmIpFetchThreadPoolMax = new ConfigKey("Advanced", Integer.class, "externaldhcp.vmipFetch.threadPool.max", "10", "number of threads for fetching vms ip address", true); @@ -2706,7 +2706,7 @@ protected void runInContext() { if (vmIdAndCount.getRetrievalCount() <= 0) { vmIdCountMap.remove(nicId); - logger.debug("Vm " + vmId +" nic "+nicId + " count is zero .. removing vm nic from map "); + logger.debug("Vm {} nic {} count is zero .. removing vm nic from map ", vmId, nicId); ActionEventUtils.onActionEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, Domain.ROOT_DOMAIN, EventTypes.EVENT_NETWORK_EXTERNAL_DHCP_VM_IPFETCH, @@ -2715,12 +2715,15 @@ protected void runInContext() { continue; } - UserVm userVm = _vmDao.findById(vmId); VMInstanceVO vmInstance = _vmInstanceDao.findById(vmId); NicVO nicVo = _nicDao.findById(nicId); - NetworkVO network = _networkDao.findById(nicVo.getNetworkId()); + if (ObjectUtils.anyNull(userVm, vmInstance, nicVo)) { + logger.warn("Couldn't fetch ip addr, Vm {} or nic {} doesn't exists", vmId, nicId); + continue; + } + NetworkVO network = _networkDao.findById(nicVo.getNetworkId()); VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(userVm); VirtualMachine vm = vmProfile.getVirtualMachine(); boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");