From b5cf0a589f616fc3ca6bdc20e0cafd31c053f925 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Fri, 7 Aug 2020 19:13:47 +0200 Subject: [PATCH] Fix SocketServer control EOF handling (#106) Handle EOF on the control pipe. This sometimes seems to happen in slow test environments even though neither end of the control pipe got closed. Now close them properly, and use the EOF event as notification instead of this.running and sending a control byte. Fixes #105 --- src/umockdev.vala | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/umockdev.vala b/src/umockdev.vala index 9846fa90..d4f49059 100644 --- a/src/umockdev.vala +++ b/src/umockdev.vala @@ -1765,12 +1765,9 @@ private class SocketServer { if (!this.running) return; - this.running = false; - // wake up the select() in our thread debug ("Stopping SocketServer: signalling thread"); - char b = '1'; - assert (Posix.write (this.ctrl_w, &b, 1) == 1); + Posix.close (this.ctrl_w); // merely calling remove_all() does not invoke ScriptRunner dtor, so stop manually foreach (unowned ScriptRunner r in this.script_runners.get_values()) @@ -1832,7 +1829,14 @@ private class SocketServer { if (Posix.FD_ISSET (this.ctrl_r, fds) > 0) { debug ("socket server thread: woken up by control fd"); char buf; - assert (Posix.read (this.ctrl_r, &buf, 1) == 1); + ssize_t r = Posix.read (this.ctrl_r, &buf, 1); + if (r == 0) { + /* EOF on ctrl_w, stop */ + this.running = false; + Posix.close (this.ctrl_r); + } else { + assert (r == 1); + } continue; }