<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body link="#0000EE" text="#000000" vlink="#551A8B" alink="#EE0000"
bgcolor="#ffffff">
Hello,<br>
<br>
Given the following Java code snipet :<br>
<blockquote type="cite"><tt> @Override</tt><tt><br>
</tt><tt> public void powerOff() throws MachineException {</tt><tt><br>
</tt><tt> Logger.track();</tt><tt><br>
</tt><tt> </tt><tt><br>
</tt><tt> IMachine machine =
ConnectionManager.findMachine(getUuid());</tt><tt><br>
</tt><tt> ISession session = ConnectionManager.getSession();</tt><tt><br>
</tt><tt> try {</tt><tt><br>
</tt><tt> machine.lockMachine(session, LockType.Shared);</tt><tt><br>
</tt><tt> IProgress p = session.getConsole().powerDown();</tt><tt><br>
</tt><tt> while (!p.getCompleted() || p.getCanceled()) {</tt><tt><br>
</tt><tt> try {</tt><tt><br>
</tt><tt>
Thread.sleep(Math.abs(p.getTimeRemaining()) * waitingCoef);</tt><tt><br>
</tt><tt> } catch (InterruptedException e) {</tt><tt><br>
</tt><tt> Logger.exception(e);</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> Logger.debug("Return code : " +
p.getResultCode());</tt><tt><br>
</tt><tt> } catch (VBoxException e) {</tt><tt><br>
</tt><tt> throw new
MachineException(e.getWrapped().getMessage());</tt><tt><br>
</tt><tt> } finally {</tt><tt><br>
</tt><tt> if
(session.getState().equals(SessionState.Locked)) {</tt><tt><br>
</tt><tt> session.unlockMachine();</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> machine.releaseRemote();</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt><tt> }</tt></blockquote>
<br>
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.<br>
<br>
When running my Unit tests, I keep having an intermitent error on
the following part :<br>
<blockquote type="cite"><tt> if
(session.getState().equals(SessionState.Locked)) {</tt><tt><br>
</tt><tt> session.unlockMachine();</tt><tt><br>
</tt><tt> }</tt><tt><br>
</tt></blockquote>
<tt><i>session.unlockMachine()</i> </tt>throws an exception with :
"<i>The session is not locked (session state: Unlocked) (0x8000FFFF)</i>".
This exception is thrown about 1 out of 5 times I use this method or
a copy of this one with only<tt> <i>.saveState()</i> </tt>instead
of<tt> <i>.powerDown()</i></tt> on the machine's console object.<tt><br>
</tt><br>
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?<br>
<br>
Thank you for your insight.<br>
<br>
Best regards,<br>
Max<br>
</body>
</html>