virtualbox-python icon indicating copy to clipboard operation
virtualbox-python copied to clipboard

GuestSession is not properly closed on failure

Open roalter opened this issue 6 years ago • 4 comments

ENVIRONMENT
  • Operating System: Windows 10
  • Python version: 2.7.10
  • VirtualBox version: 5.2.2
  • pyvbox version: 1.2.0
SUMMARY

During frequent calls to create a guest session, the amount of concurrent guest sessions overflow. In guest.py after the retries have failed, an exception is raised. This misses closing the session.

POSSIBLE FIX
def create_session(self, user, password, domain='', session_name='pyvbox',
                   timeout_ms=0):
    session = super(IGuest, self).create_session(user, password, domain,
                                                 session_name)
    for i in range(50):
        if session.status == library.GuestSessionStatus.started:
            break
        time.sleep(0.1)
    else:
        # here -> raise will not close the session. close the session forcely
        session.close()
        if len(password) == 0:
            raise SystemError('GuestSession failed to start. Could be because '
                              'of using an empty password.')
        raise SystemError("GuestSession failed to start")

roalter avatar Jan 05 '18 11:01 roalter

Yeah this is definitely an issue, do you think you could submit a Pull Request for this? :)

sethmlarson avatar Jan 05 '18 14:01 sethmlarson

Yes, of course. Still doing some other verifications, i do a pull request next week.

roalter avatar Jan 06 '18 20:01 roalter

Any updates @roalter?

sethmlarson avatar Feb 20 '18 15:02 sethmlarson

I have also encountered this issue whenever a guest session cannot be opened. Passing an incorrect password to create_session() will cause the same issue and leave the guest session in an error state with no way to close it. Running vboxmanage guestcontrol <VM_NAME> list sessions shows that the number of concurrent sessions increases for every failed attempt.

I will send a pull request to make the change proposed in this issue and ensure that the session is properly closed before returning.

busan15 avatar Mar 23 '22 13:03 busan15