* [PATCH 0/1] Work around hanging ofono
@ 2020-06-16 16:32 James Prestwood
2020-06-16 16:32 ` [PATCH 1/1] test-runner: use WNOHANG option waiting for PID James Prestwood
0 siblings, 1 reply; 2+ messages in thread
From: James Prestwood @ 2020-06-16 16:32 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 871 bytes --]
Not sure if anyone else has experienced this, but occationally any
of the tests using ofono will hang on exit. I traced this into glib
waiting for something, but that something never happens. The test
itself is executing fine and successful but ofono seems to not want
to exit gracefully. It looks to be timing dependent as it rarely
happens, and when it does adding a debug print or any other code
usually makes it go away. Even this patch itself made the issue
'go away' for me.
Obviously the proper fix is figuring out where the race condition
is in ofono, but I also think having an ultimate timeout on
kill_process() would be useful which is what this patch is adding.
James Prestwood (1):
test-runner: use WNOHANG option waiting for PID
tools/test-runner.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
--
2.21.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 1/1] test-runner: use WNOHANG option waiting for PID
2020-06-16 16:32 [PATCH 0/1] Work around hanging ofono James Prestwood
@ 2020-06-16 16:32 ` James Prestwood
0 siblings, 0 replies; 2+ messages in thread
From: James Prestwood @ 2020-06-16 16:32 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 1374 bytes --]
If an application has a bug and hangs on SIGTERM this causes
test-runner to hang as well. This is obviously an issue with
the application in question, but test-runner should have a way
of continuing onto the next test rather than hanging.
Instead we can use WNOHANG and a sleep to allow applications
some amount of time to exit, and if they haven't use SIGKILL
instead as well as print an error. Similar to how
wait_for_socket works. The timeout is hard coded to 2 seconds
(100ms sleep + 20 iterations).
---
tools/test-runner.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/test-runner.c b/tools/test-runner.c
index f8677be5..498f3be3 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -626,14 +626,23 @@ exit:
static void kill_process(pid_t pid)
{
int status;
+ int i = 0;
l_debug("Terminate pid: %d", pid);
kill(pid, SIGTERM);
do {
- waitpid(pid, &status, 0);
- } while (!WIFEXITED(status) && !WIFSIGNALED(status));
+ if (waitpid(pid, &status, WNOHANG) == pid)
+ return;
+
+ usleep(100000);
+ } while (!WIFEXITED(status) && !WIFSIGNALED(status) && i++ < 20);
+
+ if (i >= 20) {
+ l_error("Failed to kill process %d gracefully", pid);
+ kill(pid, SIGKILL);
+ }
}
static bool wait_for_socket(const char *socket, useconds_t wait_time)
--
2.21.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-16 16:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-16 16:32 [PATCH 0/1] Work around hanging ofono James Prestwood
2020-06-16 16:32 ` [PATCH 1/1] test-runner: use WNOHANG option waiting for PID James Prestwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox