[vbox-dev] Race condition?

Maxime Dor maxime.dor at altherian.org
Sat Feb 23 02:17:15 GMT 2013


Hello,

Given the following Java code snipet :
>    @Override
>    public void powerOff() throws MachineException {
>       Logger.track();
>
>       IMachine machine = ConnectionManager.findMachine(getUuid());
>       ISession session = ConnectionManager.getSession();
>       try {
>          machine.lockMachine(session, LockType.Shared);
>          IProgress p = session.getConsole().powerDown();
>          while (!p.getCompleted() || p.getCanceled()) {
>             try {
> Thread.sleep(Math.abs(p.getTimeRemaining()) * waitingCoef);
>             } catch (InterruptedException e) {
>                Logger.exception(e);
>             }
>          }
>          Logger.debug("Return code : " + p.getResultCode());
>       } catch (VBoxException e) {
>          throw new MachineException(e.getWrapped().getMessage());
>       } finally {
>          if (session.getState().equals(SessionState.Locked)) {
>             session.unlockMachine();
>          }
>          machine.releaseRemote();
>       }
>    }

I am running this using the 4.2 API (from the 4.2.4 SDK to be precise) 
against Web Services running on a Debian Testing box.

When running my Unit tests, I keep having an intermitent error on the 
following part :
>          if (session.getState().equals(SessionState.Locked)) {
>             session.unlockMachine();
>          }
/session.unlockMachine()/ throws an exception with : "/The session is 
not locked (session state: Unlocked) (0x8000FFFF)/". This exception is 
thrown about 1 out of 5 times I use this method or a copy of this one 
with only/.saveState()/ instead of/.powerDown()/ on the machine's 
console object.

Am I missing something? From what I see here, it looks like the session 
state changes between the IF statement and the actual unlockMachine() 
call, looking like a race condition - or a bug?

Thank you for your insight.

Best regards,
Max
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20130223/44523578/attachment.html>


More information about the vbox-dev mailing list