canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.38k stars 931 forks source link

LXD 4.23 fork proxy’s are active around after the instance that used them is been –force deleted #9950

Closed Dweller closed 2 years ago

Dweller commented 2 years ago

Required information

Issue description

After creating a LXD instance using the AlmaLinux cloud image I've created a proxy from the host to the instance from host:8080 to instance:80. This works and no problems to this point. However when I force delete the running instance the forkproxy for the [prt 8080->80 still remains and prevents the creation of a new proxy on the same ports to a new container.

Steps to reproduce

  1. Create a cloud instance container and assign a TCP proxy port I use a python script and a pylxd method of..
    con = lxd.containers.get(name)
    con.devices['fcgi808'+id] = {'connect': 'tcp:127.0.0.1:80', 'listen': 'tcp:0.0.0.0:808'+id, 'type': 'proxy'}
    res = con.save()
  2. Confirm the proxy works.. (Mines bound to nginx on port 80) using curl or wget to localhost:8080 on the host
  3. lxd delete --force
  4. confirm that the instance has been deleted using 'lxc list'
  5. check the status with ps that the forkproxy e.g. 1000000 138075 9744 0 10:03 ? 00:00:00 /snap/lxd/current/bin/lxd forkproxy -- 9744 -1 tcp:0.0.0.0:8080 131212 -1 tcp:127.0.0.1:80 0644
tomponline commented 2 years ago

Was the container running when the proxy device was added?

tomponline commented 2 years ago

Looking at this now to see if I can recreate.

tomponline commented 2 years ago

I've used this test and have not been able to reproduce:

lxc launch images:ubuntu/focal c1
lxc exec c1 -- apt install nginx -y
lxc exec c1 -- systemctl enable nginx --now
lxc config device add c1 p1 proxy listen=tcp:0.0.0.0:8080 connect=tcp:127.0.0.1:80
curl http://127.0.0.1:8080
lxc stop -f c1
ps aux | grep forkproxy
lxc delete -f c1

Please can you provide a reproducer using the lxc commands and show how the service inside the instance is running (i.e is it reproducible with something that can be installed from the distribution like nginx in my test)?

tomponline commented 2 years ago

Also can you consult the debug log when this occurs:

sudo snap set lxd daemon.debug=true; sudo systemctl reload snap.lxd.daemon
sudo tail -f /var/snap/lxd/common/lxd/logs/lxd.log

And see if there are any errors or entries regarding the proxy device name and its stop process?

tomponline commented 2 years ago

I've also tested this using the snap lxd 4.23 package on ubuntu 20.04 with stock kernel and couldn't recreate.