|
239 | 239 | import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary; |
240 | 240 | import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary; |
241 | 241 | import com.cloud.hypervisor.vmware.util.VmwareContext; |
| 242 | +import com.cloud.hypervisor.vmware.util.VmwareContextPool; |
242 | 243 | import com.cloud.hypervisor.vmware.util.VmwareHelper; |
243 | 244 | import com.cloud.network.Networks; |
244 | 245 | import com.cloud.network.Networks.BroadcastDomainType; |
@@ -4794,14 +4795,21 @@ public VmwareContext getServiceContext(Command cmd) { |
4794 | 4795 | VmwareContext context = null; |
4795 | 4796 | if(s_serviceContext.get() != null) { |
4796 | 4797 | context = s_serviceContext.get(); |
4797 | | - if (context.validate()) { |
4798 | | - if (s_logger.isTraceEnabled()) { |
4799 | | - s_logger.trace("ThreadLocal context is still valid, just reuse"); |
| 4798 | + String poolKey = VmwareContextPool.composePoolKey(_vCenterAddress, _username); |
| 4799 | + // Before re-using the thread local context, ensure it corresponds to the right vCenter API session and that it is valid to make calls. |
| 4800 | + if(context.getPoolKey().equals(poolKey)) { |
| 4801 | + if (context.validate()) { |
| 4802 | + if (s_logger.isTraceEnabled()) { |
| 4803 | + s_logger.trace("ThreadLocal context is still valid, just reuse"); |
| 4804 | + } |
| 4805 | + return context; |
| 4806 | + } else { |
| 4807 | + s_logger.info("Validation of the context failed, dispose and use a new one"); |
| 4808 | + invalidateServiceContext(context); |
4800 | 4809 | } |
4801 | | - return context; |
4802 | 4810 | } else { |
4803 | | - s_logger.info("Validation of the context failed, dispose and use a new one"); |
4804 | | - invalidateServiceContext(context); |
| 4811 | + // Exisitng ThreadLocal context corresponds to a different vCenter API session. Why has it not been recycled? |
| 4812 | + s_logger.warn("ThreadLocal VMware context: " + poolKey + " doesn't correspond to the right vCenter. Expected VMware context: " + context.getPoolKey()); |
4805 | 4813 | } |
4806 | 4814 | } |
4807 | 4815 | try { |
|
0 commit comments