Packer: virtualbox-iso error: machine is already locked for a session (or being unlocked)

Created on 4 Oct 2017  ยท  4Comments  ยท  Source: hashicorp/packer

packer version: 1.1.0
VirtualBox: 5.1.28
OS: CentOS 7.4

==> virtualbox-iso: Gracefully halting virtual machine...
==> virtualbox-iso: Preparing to export machine...
    virtualbox-iso: Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port 3289)
==> virtualbox-iso: Error deleting port forwarding rule: VBoxManage error: VBoxManage: error: The machine 'centos7' is already locked for a session (or being unlocked)
==> virtualbox-iso: VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
==> virtualbox-iso: VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 507 of file VBoxManageModifyVM.cpp
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Error deleting virtual machine: VBoxManage error: VBoxManage: error: Cannot unregister the machine 'centos7' while it is locked
==> virtualbox-iso: VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
==> virtualbox-iso: VBoxManage: error: Context: "Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(aMedia))" at line 156 of file VBoxManageMisc.cpp
==> virtualbox-iso: Deleting output directory...
Build 'virtualbox-iso' errored: Error deleting port forwarding rule: VBoxManage error: VBoxManage: error: The machine 'centos7' is already locked for a session (or being unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 507 of file VBoxManageModifyVM.cpp

==> Some builds didn't complete successfully and had errors:
--> virtualbox-iso: Error deleting port forwarding rule: VBoxManage error: VBoxManage: error: The machine 'centos7' is already locked for a session (or being unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 507 of file VBoxManageModifyVM.cpp

==> Builds finished but no artifacts were created.
make: *** [box/virtualbox/centos7-20171004.box] Error 1

"post_shutdown_delay": "30s" has no impact. headless/non-headless makes no difference.

When I ran packer in debug mode, it finished fine. It seems there is a timing issue and in debug mode things slow down enough that VirtualBox has enough time to remove the locks (or whatever it's trying to do).

bug buildevirtualbox

Most helpful comment

@mwhooker increasing it to 2min fixed the issue. Thank you!

All 4 comments

I wonder if you need to increase the post_shutdown_delay to something like 2 minutes, which is generally around when these types of issues seem to go away. Otherwise, I think adding a retry as with https://github.com/hashicorp/packer/issues/4432 would work.

Can you reproduce this reliably?

If it doesn't work on headless mode, then this is different from #1193

@mwhooker increasing it to 2min fixed the issue. Thank you!

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings