cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Darren Shepherd <>
Subject race conditions in VolumeServiceImpl.createBaseImageAsync() creates NPE
Date Thu, 31 Oct 2013 18:39:29 GMT
The following code results in a NPE in bad situations

        templatePoolRef =

        if (templatePoolRef == null) {
            if (s_logger.isDebugEnabled()) {
      "Unable to acquire lock on
VMTemplateStoragePool " + templatePoolRefId);
            templatePoolRef =
_tmpltPoolDao.findByPoolTemplate(dataStore.getId(), template.getId());
            if (templatePoolRef.getState() ==
ObjectInDataStoreStateMachine.State.Ready ) {
      "Unable to acquire lock on
VMTemplateStoragePool " + templatePoolRefId + ", But Template " +
template.getUniqueName() + " is already copied to primary storage, skip
templateOnPrimaryStoreObj, dataStore, future);
            throw new CloudRuntimeException("Unable to acquire lock on
VMTemplateStoragePool: " + templatePoolRefId);

If two threads are trying to stage the same template thread one gets the
lock, thread two will wait.  If thread one fails to stage the template it
will delete the templatePoolRef from the database.  Thread two will now get
the lock in op_lock, but the internal findById will not find a
templatePoolRef because it has been deleted and return null from
acquireInLockTable().  Technically thread two has the lock, but the ref
templatePoolRef wasn't found.  The subsequent line "templatePoolRef =
_tmpltPoolDao.findByPoolTemplate(...)" will return null, because it doesn't
exist and then on the next line templatePoolRef.getState() will throw a NPE.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message