Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vagrant destroy kills too many interfaces #1324

Closed
rottenbytes opened this issue Jan 17, 2013 · 13 comments
Closed

vagrant destroy kills too many interfaces #1324

rottenbytes opened this issue Jan 17, 2013 · 13 comments

Comments

@rottenbytes
Copy link

When working on a multi users environment, each with its vagrant setup (and vboxnet interface, for network isolation, routing) vagrant kills too many interfaces on destroy

sample ifconfig output before:

[snip]

lo        Link encap:Local Loopback··
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:125499 errors:0 dropped:0 overruns:0 frame:0
          TX packets:125499 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0·
          RX bytes:11811259 (11.2 MiB)  TX bytes:11811259 (11.2 MiB)

vboxnet0  Link encap:Ethernet  HWaddr 0a:00:27:00:00:00··
          inet addr:10.231.40.1  Bcast:10.231.40.255  Mask:255.255.255.0
          inet6 addr: fe80::800:27ff:fe00:0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000·
          RX bytes:0 (0.0 B)  TX bytes:978 (978.0 B)

vboxnet1  Link encap:Ethernet  HWaddr 0a:00:27:00:00:01··
          inet addr:10.231.42.1  Bcast:10.231.42.255  Mask:255.255.255.0
          inet6 addr: fe80::800:27ff:fe00:1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:333 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000·
          RX bytes:0 (0.0 B)  TX bytes:15282 (14.9 KiB)

vboxnet2  Link encap:Ethernet  HWaddr 0a:00:27:00:00:02··
          inet addr:10.231.41.1  Bcast:10.231.41.255  Mask:255.255.255.0
          inet6 addr: fe80::800:27ff:fe00:2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4240 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000·
          RX bytes:0 (0.0 B)  TX bytes:186252 (181.8 KiB)

then "vagrant destroy aVM"

sample output after :

[snip]

lo        Link encap:Local Loopback··
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:125499 errors:0 dropped:0 overruns:0 frame:0
          TX packets:125499 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0·
          RX bytes:11811259 (11.2 MiB)  TX bytes:11811259 (11.2 MiB)

vboxnet2  Link encap:Ethernet  HWaddr 0a:00:27:00:00:02··
          inet addr:10.231.41.1  Bcast:10.231.41.255  Mask:255.255.255.0
          inet6 addr: fe80::800:27ff:fe00:2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4240 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000·
          RX bytes:0 (0.0 B)  TX bytes:186252 (181.8 KiB)

and if the user with VMs linked to vboxnet2 destroys a VM, then vboxneti0 and vboxnet1 get destroyed. The vms do not get killed or harmed, but they lose the network.

Each VM has 2 interfaces, 1st one is using vbox DHCP, and the second one is a hostonly one (used in routing)
sample VagrantFile entry

config.vm.define :trash1 do |trash1_config|
  trash1_config.vm.forward_port(22,14026)
  trash1_config.vm.host_name = "trash1.sandboxnico.loc"
  trash1_config.vm.network :hostonly, "10.231.40.6"
  trash1_config.vm.provision :shell, :path => "bootstrap_managed.sh"
  trash1_config.vm.customize ["modifyvm", :id, "--memory", 256]
end

My guess is that the code in the function "delete_unused_host_only_networks" (plugins/providers/virtualbox/driver/version_4_2.rb:67) is not aware of the multi users aspect of the usage, then kills interfaces that seem unused to it.

additionnal informations :

  • Vagrant version : 1.0.6 (same in 1.0.5)
  • Virtualbox version : 4.2
  • OS : Debian squeeze
@mitchellh
Copy link
Contributor

You're correct. I detect unused network interfaces by inspecting all VMs that VirtualBox knows about. This does not include (rightfully) other user's virtual machines.

Do you have an idea of how to better do this check? I'm investigating but nothing jumps out to me yet.

@rottenbytes
Copy link
Author

As you can't see other users VMs with "VBoxManage list " it seems that the solution is going to be hard to find.

I see 2 options :

  • add a flag (or config option) in vagrant to disable that cleanup. This could also be done at confirmation on the destroy dialog.
  • remove the cleanup (probably not wanted)

@eedgar
Copy link

eedgar commented Jan 30, 2013

How about you record in the file which ones vagrant created via comments in
the files? Then cleanup those based on the comments?

On Wed, Jan 30, 2013 at 3:07 AM, Nicolas Szalay notifications@github.comwrote:

As you can't see other users VMs with "VBoxManage list " it seems that the
solution is going to be hard to find.

I see 2 options :

  • add a flag (or config option) in vagrant to disable that cleanup

  • remove the cleanup (probably not wanted)


    Reply to this email directly or view it on GitHubhttps://github.com/vagrant destroy kills too many interfaces #1324#issuecomment-12880345.

@rottenbytes
Copy link
Author

It was an option we talked about with my colleagues, but if the interface gets reused by vbox for another user he will be stuck.

@marsmensch
Copy link

Tough challenge..... i looked through all modifyvm parameters but found none to be suited for the cause.
Given that this is a corner case i would also prefer to have a flag (or config option) in vagrant to disable that cleanup.

@mitchellh
Copy link
Contributor

I'm actually running into this same challenge with the VMware Fusion provider that I have been working on. Fusion provides no central way to do this same thing. With Fusion I decided to just punt on the issue and just put up a "known issues" page that covers this limitation.

Perhaps I should just do the same with VirtualBox.

@mitchellh
Copy link
Contributor

Coming back to this finally. So, the VMware provider, used by thousands of people, doesn't clean up network interfaces. It never has. And nobody has complained. Maybe the solution to this is to just actually disable that code path...

@rottenbytes
Copy link
Author

Agreed 👍

@omribahumi
Copy link

Here's how I patched my Vagrantfile to disable this behaviour on Virtualbox:

[VagrantPlugins::ProviderVirtualBox::Driver::Version_4_1, VagrantPlugins::ProviderVirtualBox::Driver::Version_4_2].each do |cls|
  cls.class_eval do
    def delete_unused_host_only_networks
      puts "delete_unused_host_only_networks discarded"
    end
  end
end

@mitchellh
Copy link
Contributor

Vagrant no longer removes unused network interfaces and leaves it up to the user. This can forcibly be re-enabled using VirtualBox provider-specific config:

config.vm.provider "virtualbox" do |v|
  v.destroy_unused_network_interfaces = true
end

@tknerr
Copy link
Contributor

tknerr commented Jul 26, 2013

cool stuff - that was always annoying on windows... 👍

dldinternet pushed a commit to dldinternet/vagrant that referenced this issue Aug 26, 2013
dldinternet pushed a commit to dldinternet/vagrant that referenced this issue Sep 1, 2013
@jameshilliard
Copy link

I think this is being handled wrong still for private networks. If no IP is specified vagrant should first attempt to match the guest static IP to any existing host-only adapters before generating a new one, otherwise multiple adapters end up being generated, at a minimum there should be an option for this. It should also have the ability to disable/reconfigure dhcp for that network if needed as opposed to just generating more adapters. Generating more than 1 host-only adapter should really be a last resort used if its impossible to use/reconfigure existing ones.

@richard-scott
Copy link

I have noticed that Vagrant may not remove "vboxnet0" anymore, but it does shut down the interface, and remove its IP making it useless still ;-(

@hashicorp hashicorp locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants