5.0.2 raises "Connection reset by peer" exception on pylxd's container.execute()

Reverting to 5.0.1 makes this not happen anymore. For the record, I’m running Ubuntu 22.04 with pylxd 2.3.1.

Note that the execute happens properly anyway, so this is more of an annoyance than anything functionally broken.

Here is the backtrace:

Failed to receive data
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/ws4py/websocket.py", line 394, in once
    b = self.sock.recv(self.reading_buffer_size)
ConnectionResetError: [Errno 104] Connection reset by peer

Example python script used to reproduce the failure:

#!/usr/bin/env python3

import pylxd
import sys

name = sys.argv[1]
client = pylxd.Client()
container = client.containers.get(name)

_, stdout, _ = container.execute(['echo', 'Hello'])
print(stdout)

Thank you for this report and example script, I will try and reproduce.

Looks like there is a fix for this in edge: https://github.com/lxc/pylxd/commit/9e73391db1437f88fc00d36c1b023c9eaf0d35ea

Try:

pip install git+https://github.com/lxc/pylxd

It looks like pylxd is closing the control socket before its finished reading from stdout socket.

The ordering of the socket closes is different than when using lxc exec --force-noninteractive