]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commit
oeqa ssh.py: fix hangs in run()
authorMikko Rapeli <mikko.rapeli@linaro.org>
Wed, 15 Feb 2023 14:50:40 +0000 (16:50 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 20 Feb 2023 15:18:32 +0000 (15:18 +0000)
commit9c63970fce3a3d6029745252a6ec2bf9b9da862d
treeb33a54fe8ce9f71fd9f75b687c10f22a47b063c6
parentc79c895269050c44134a16ab6801c06b9497cf37
oeqa ssh.py: fix hangs in run()

When qemu machine hangs, the ssh commands done by tests
are not timing out. do_testimage() task has last logs like this:

DEBUG: time: 1673531086.3155053, endtime: 1673531686.315502

The test process is stuck for hours, or for ever if the
executing command or test case did not set a timeout correctly.
The default 300 second timeout is not working when target hangs.
Note that timeout is really a "inactive timeout" since data returned
by the process will reset the timeout.

Make the process stdout non-blocking so read() will always return
right away using os.set_blocking() available in python 3.5 and later.

Then change from python codec reader to plain read() and make
the ssh subprocess stdout non-blocking. Even with select()
making sure the file had input to be read, the codec reader was
trying to find more stuff and blocking for ever when process hangs.

While at it, add a small timeout to read data in larger chunks if
possible. This avoids reading data one or few characters at a time
and makes the debug logs more readable.

close() the stdout file in all cases after read loop is complete.

Then make sure to wait or kill the ssh subprocess in all cases.
Just reading the output stream and receiving EOF there does not mean
that the process exited, and wait() needs a timeout if the process
is hanging. In the end kill the process and return the return value
and captured output utf-8 encoded, just like before these changes.

This fixes ssh run() related deadlocks when a qemu target hangs
completely.

Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
meta/lib/oeqa/core/target/ssh.py