VirtualBox

Opened 10 years ago

Closed 8 years ago

#12428 closed defect (obsolete)

Shutting down VM using XPCOM API hangs

Reported by: blueg3 Owned by:
Component: VM control Version: VirtualBox 4.3.4
Keywords: Cc:
Guest type: other Host type: other

Description

On a Linux host system, I have a multithreaded application that uses the VirtualBox XPCOM API to frequently start and shut down VMs.

Occasionally, it appears that part of the VM shutdown process hangs when shutting down a VM.

This is, roughly, what I'm doing in code, with a lot of error checking elided:

ComPtr<IMachine> machine = ...;
ComPtr<ISession> session = ...;

com::NativeEventQueue::getMainEventQueue()->processEventQueue(0);
ComPtr<IConsole> console;
HRESULT hrc = session->COMGETTER(Console)( console.asOutParam() );
ComPtr<IProgress> progress;
hrc = console->PowerDown( progress.asOutParam() );
HRESULT hrc = progress->WaitForCompletion( 5 * 60 * 1000 );
// get some information from progress
session->UnlockMachine();
com::NativeEventQueue::getMainEventQueue()->processEventQueue(0);
HRESULT hrc = machine->LockMachine( (*(vm->session)), LockType_Shared ); // done in a loop until successful
// get a new machine and session and proceed to restore snapshot

WaitForCompletion() completes successfully. The VM is marked as "Powered Off" in the VirtualBox GUI. The process associated with the VM doesn't terminate. Somewhere in the above code between UnlockMachine() and restoring a snapshot (inclusive), the code hangs indefinitely. Killing the VM's process (SIGTERM) causes the code to unhang and continue without any obvious ill effects.

In GDB, my thread that appears to be trying to shut the VM down has this stack trace:

#0  pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238
#1  0x00007fc5ecb3805a in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#2  0x00007fc5ecb384b1 in VBoxNsprPR_WaitCondVar () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#3  0x00007fc5ecb3876c in VBoxNsprPR_Wait () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#4  0x00007fc5e5d41d2a in ?? () from /opt/VirtualBox-FTN-0.1.0/components/VBoxXPCOMIPCC.so
#5  0x00007fc5e5d41faf in ?? () from /opt/VirtualBox-FTN-0.1.0/components/VBoxXPCOMIPCC.so
#6  0x00007fc5e5d4a2af in ?? () from /opt/VirtualBox-FTN-0.1.0/components/VBoxXPCOMIPCC.so
#7  0x00007fc5ecb33aa0 in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#8  0x00007fc5ecb32ebb in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#9  0x00007fc5cc001250 in ?? ()
#10 0x00007fc5cc0009c0 in ?? ()
#11 0x0000000000000001 in ?? ()
#12 0x0000000000000000 in ?? ()

Most of the VirtualBox nspr-N (N = 1..5) threads appear to be in pthread_cond_wait:

#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007fc5ecb3849d in VBoxNsprPR_WaitCondVar () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#2  0x00007fc5ecb3876c in VBoxNsprPR_Wait () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#3  0x00007fc5e5d49c94 in ?? () from /opt/VirtualBox-FTN-0.1.0/components/VBoxXPCOMIPCC.so
#4  0x00007fc5ecb27001 in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#5  0x00007fc5ecb372ca in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#6  0x00007fc5ec792a1c in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxRT.so
#7  0x00007fc5ec7f660c in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxRT.so
#8  0x00007fc5ebcd3f8e in start_thread (arg=0x7fc5ecf06700) at pthread_create.c:311
#9  0x00007fc5eb9fda0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

However, nspr-1 is in poll():

#0  0x00007fc5eb9f0fbd in poll () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007fc5ecb39532 in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#2  0x00007fc5ecb3c244 in VBoxNsprPR_Poll () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#3  0x00007fc5e5d4ddab in ?? () from /opt/VirtualBox-FTN-0.1.0/components/VBoxXPCOMIPCC.so
#4  0x00007fc5ecb372ca in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxXPCOM.so
#5  0x00007fc5ec792a1c in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxRT.so
#6  0x00007fc5ec7f660c in ?? () from /opt/VirtualBox-FTN-0.1.0/VBoxRT.so
#7  0x00007fc5ebcd3f8e in start_thread (arg=0x7fc5ecf8a700) at pthread_create.c:311
#8  0x00007fc5eb9fda0d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

The VM process itself is in a futex() loop. According to strace:

futex(0x7f4d98, FUTEX_WAKE_PRIVATE, 1)  = 1
futex(0x7f4d48, FUTEX_WAKE_PRIVATE, 1)  = 1
futex(0x7f4d4c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 8533, {1387274436, 607408000}, ffffffff) = 0

Log file from the VM is attached (slightly redacted).

This seems like a race condition. I have a number of VMs that are nearly identical starting up and shutting down and this only occurs every once in a while, usually under high load (frequent startup / shutdown events).

Attachments (1)

lockup-vbox.log (85.6 KB ) - added by blueg3 10 years ago.
Vbox.log

Download all attachments as: .zip

Change History (4)

by blueg3, 10 years ago

Attachment: lockup-vbox.log added

Vbox.log

comment:1 by Scott.Liu, 10 years ago

I am working under Mac OSX, and want to write a tool use virtual box with XPCOM, but when I included XPCOM headers into my project, which developed under Qt, some error occurred. like below:

Undefined symbols for architecture x86_64:
  "_NS_InitXPCOM2", referenced from:
      VBoxWrapper::VBoxWrapper() in vboxwrapper.o
  "nsCOMPtr_base::begin_assignment()", referenced from:
      nsCOMPtr<nsIServiceManager>::StartAssignment() in vboxwrapper.o
  "nsCOMPtr_base::~nsCOMPtr_base()", referenced from:
      nsCOMPtr<nsIServiceManager>::~nsCOMPtr() in vboxwrapper.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [VBoxWithGlue.app/Contents/MacOS/VBoxWithGlue] Error 1

I think there is two reasons may cause the error:

  1. I didn't install Virtualbox SDK on my Mac; Although I am sure virtual box installed on Mac, and I download SDK and run python code to install SDK, I still not found xpcom.dylib and other dylibs which XPCOM needs. So IS THERE ANYBODY KNOWS HOW TO INSTALL VIRTUALBOX SDK ON Mac?
  1. I am not sure I write correct code to use XPCOM. Since I didn't found valuable demo to use vbox XPCOM API, I am not sure I find the right way.

please help me if you know something about VirtualBox on Mac, thank you!

Last edited 8 years ago by Frank Mehnert (previous) (diff)

comment:2 by Frank Mehnert, 10 years ago

Scott.Liu, please ask such questions in the forums (forums.virtualbox.org)!

comment:3 by aeichner, 8 years ago

Resolution: obsolete
Status: newclosed

Please reopen if still relevant with a recent VirtualBox release.

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use