diff mbox series

[v2,7/8] oeqa qemurunner.py: kill qemu if it hangs

Message ID 20230209080936.148489-8-mikko.rapeli@linaro.org
State New
Headers show
Series fix oeqa runtime test framework when qemu hangs | expand

Commit Message

Mikko Rapeli Feb. 9, 2023, 8:09 a.m. UTC
qemu doesn't always behave well and can hang too.
kill it with force if was still alive.

Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
---
 meta/lib/oeqa/utils/qemurunner.py | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Alexander Kanavin Feb. 9, 2023, 9:45 a.m. UTC | #1
Isn't the code waiting 5 seconds and then sending SIGKILL, regardless
of whether SIGTERM was successful or not here?

I would actually remove this function altogether. qemu process is
started by runqemu and it's the job of that to clean up the actual
qemu process properly.

Alex

On Thu, 9 Feb 2023 at 09:10, Mikko Rapeli <mikko.rapeli@linaro.org> wrote:
>
> qemu doesn't always behave well and can hang too.
> kill it with force if was still alive.
>
> Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
> ---
>  meta/lib/oeqa/utils/qemurunner.py | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
> index bce00c696a..8e3484385d 100644
> --- a/meta/lib/oeqa/utils/qemurunner.py
> +++ b/meta/lib/oeqa/utils/qemurunner.py
> @@ -589,6 +589,13 @@ class QemuRunner:
>                  os.kill(self.qemupid, signal.SIGTERM)
>              except ProcessLookupError as e:
>                  self.logger.warning('qemu-system ended unexpectedly')
> +            time.sleep(5)
> +            try:
> +                # qemu-system did not behave well
> +                os.kill(self.qemupid, signal.SIGKILL)
> +            except ProcessLookupError as e:
> +                # already dead
> +                pass
>
>      def stop_thread(self):
>          if self.thread and self.thread.is_alive():
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#176926): https://lists.openembedded.org/g/openembedded-core/message/176926
> Mute This Topic: https://lists.openembedded.org/mt/96849162/1686489
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Mikko Rapeli Feb. 9, 2023, 9:56 a.m. UTC | #2
Hi,

On Thu, Feb 09, 2023 at 10:45:36AM +0100, Alexander Kanavin wrote:
> Isn't the code waiting 5 seconds and then sending SIGKILL, regardless
> of whether SIGTERM was successful or not here?

Yes. Not nice but better than leaking the process completely.

> I would actually remove this function altogether. qemu process is
> started by runqemu and it's the job of that to clean up the actual
> qemu process properly.

It doesn't currently. Should the sigterm_handler() also use SIGKILL if
it has to?

Cheers,

-Mikko

> Alex
> 
> On Thu, 9 Feb 2023 at 09:10, Mikko Rapeli <mikko.rapeli@linaro.org> wrote:
> >
> > qemu doesn't always behave well and can hang too.
> > kill it with force if was still alive.
> >
> > Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
> > ---
> >  meta/lib/oeqa/utils/qemurunner.py | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
> > index bce00c696a..8e3484385d 100644
> > --- a/meta/lib/oeqa/utils/qemurunner.py
> > +++ b/meta/lib/oeqa/utils/qemurunner.py
> > @@ -589,6 +589,13 @@ class QemuRunner:
> >                  os.kill(self.qemupid, signal.SIGTERM)
> >              except ProcessLookupError as e:
> >                  self.logger.warning('qemu-system ended unexpectedly')
> > +            time.sleep(5)
> > +            try:
> > +                # qemu-system did not behave well
> > +                os.kill(self.qemupid, signal.SIGKILL)
> > +            except ProcessLookupError as e:
> > +                # already dead
> > +                pass
> >
> >      def stop_thread(self):
> >          if self.thread and self.thread.is_alive():
> > --
> > 2.34.1
> >
> >
> > -=-=-=-=-=-=-=-=-=-=-=-
> > Links: You receive all messages sent to this group.
> > View/Reply Online (#176926): https://lists.openembedded.org/g/openembedded-core/message/176926
> > Mute This Topic: https://lists.openembedded.org/mt/96849162/1686489
> > Group Owner: openembedded-core+owner@lists.openembedded.org
> > Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [alex.kanavin@gmail.com]
> > -=-=-=-=-=-=-=-=-=-=-=-
> >
Alexander Kanavin Feb. 9, 2023, 10:01 a.m. UTC | #3
On Thu, 9 Feb 2023 at 10:56, Mikko Rapeli <mikko.rapeli@linaro.org> wrote:
> It doesn't currently. Should the sigterm_handler() also use SIGKILL if
> it has to?

Yes please. Let's not duplicate functionality. And please do try to
avoid adding hard sleep(), there are usually ways to do things
synchronously.

Alex
diff mbox series

Patch

diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index bce00c696a..8e3484385d 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -589,6 +589,13 @@  class QemuRunner:
                 os.kill(self.qemupid, signal.SIGTERM)
             except ProcessLookupError as e:
                 self.logger.warning('qemu-system ended unexpectedly')
+            time.sleep(5)
+            try:
+                # qemu-system did not behave well
+                os.kill(self.qemupid, signal.SIGKILL)
+            except ProcessLookupError as e:
+                # already dead
+                pass
 
     def stop_thread(self):
         if self.thread and self.thread.is_alive():