Skip to content

Commit

Permalink
Fix in-use VNC socket detection for qemu
Browse files Browse the repository at this point in the history
The `qemu_vm` probes the availability of a free VNC port by creating
a socket and binding to it. If that succeeds, the port is considered
free.

The problem is that `find_free_ports()` in the avocado network utils
defaults to "localhost" (=127.0.0.1) for the socket address while
qemu later binds the VNC port to "0.0.0.0".

Starting with kernel 6.2.8 / 6.3.x+, the kernel behavior changed.
While the avocado code considered a port as available, later on
the start of qemu using that port failed with an "in use socket".

As qemu additionally uses SO_REUSEADDR for the socket and this allows
certain socket configuration to both bind for 0.0.0.0 and 127.0.0.1.
It's unclear if the new kernel behavior is 100% correct, but it does
not matter since the correct thing to do is to use the matching socket
address 0.0.0.0 in avocado. Broken behavior has been tested with kernel
6.2.8, 6.4.15, 6.5.5 and 6.6.13. Fix has been confirmed using the last.

May be related:
https://lore.kernel.org/netdev/[email protected]/T/#m34ca2f2765e5532243c7d20a4279baccf2ef9194
torvalds/linux@28044fc
  • Loading branch information
thomasjfox authored and pevogam committed Feb 13, 2024
1 parent e3440ed commit aa8ee99
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion virttest/qemu_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3025,7 +3025,7 @@ def create(self, name=None, params=None, root_dir=None,

# Find available VNC port, if needed
if params.get("display") == "vnc":
self.vnc_port = utils_misc.find_free_port(5900, 6900, sequent=True)
self.vnc_port = utils_misc.find_free_port(5900, 6900, address='0.0.0.0', sequent=True)

# Find random UUID if specified 'uuid = random' in config file
if params.get("uuid") == "random":
Expand Down

0 comments on commit aa8ee99

Please sign in to comment.