Closed matthijskooijman closed 1 month ago
I'm guessing the error was introduced during
The changes remove the host.connection
attribute in favor of some other attribute including host.connected
.
Yet, server.reboot
still makes use of host.connection
:
https://github.com/pyinfra-dev/pyinfra/blob/a7be6892254e32271aca92bca47fbf6edd18e743/pyinfra/operations/server.py#L89-L95
A quick fix is to replace host.connection
with host.connected
in server.reboot
.
Great catch, agree reboot should disconnect properly here and we should fix the timeout issue too!
Describe the bug
When using
server.reboot
, pyinfra reboots the target but then waits for it to come back until the timeout, even if the system comes up earlier.To Reproduce
Result:
Expected behavior
The server should reboot, when it is rebooted pyinfra should continue (or exit with success in this example).
Analysis
I added some debug output, and it turns out that
Host.connect
is called repeatedly to try making a new connection, buthost.connected
is true, so no actual connection attempts are made: https://github.com/pyinfra-dev/pyinfra/blob/80aca6e3ea9e2c1e423505abf1f5ef9c2c4affdc/pyinfra/api/host.py#L365Looking at the code, there is no way to make
host.connected
False again (except for creating a new Host object). So I wonder:server.reboot
should be callinghost.disconnect()
to explicitly terminate the connection (because the TCP connection might otherwise linger and take some time to be detected as failed).host.disconnect
should setconnected=False
?server.reboot
already setshost.connection
to None, and then uses that to check whether the connection was succesful. Is this proper use of the host API, or isserver.reboot
messing with internals? Shouldserver.reboot
even check for a succesfulconnection after the fact, or should it passraise_exceptions
and then detect connection success by the absence of an exception?(and an unrelated observation: It seems the timeout is not properly observed, since currently the timeout is divided by the interval to get the number of retries, but this assumes connection attempts take zero time, which is not true, especially when a system is rebooting, they might take longer).
Meta
Installed via pipx.