diff mbox series

[7/8] libxl: event: Fix possible hang with libxl_osevent_beforepoll

Message ID 20200110132902.29295-8-ian.jackson@eu.citrix.com (mailing list archive)
State Superseded
Headers show
Series libxl: event: Fix hang for some applications | expand

Commit Message

Ian Jackson Jan. 10, 2020, 1:29 p.m. UTC
If the application uses libxl_osevent_beforepoll, a similar hang is
possible to the one described and fixed in
   libxl: event: Fix hang when mixing blocking and eventy calls
Application behaviour would have to be fairly unusual, but it
doesn't seem sensible to just leave this latent bug.

We fix the latent bug by waking up the "poller_app" pipe every time we
add osevents.  If the application does not ever call beforepoll, we
write one byte to the pipe and set pipe_nonempty and then we ignore
it.  We only write another byte if beforepoll is called again.

Normally in an eventy program there would only be one thread calling
libxl_osevent_beforepoll.  The effect in such a program is to
sometimes needlessly go round the poll loop again if a timeout
callback becomes interested in a new osevent.  We'll fix that in a
moment.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 tools/libxl/libxl_event.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/tools/libxl/libxl_event.c b/tools/libxl/libxl_event.c
index 4d57843cce..4314191c3b 100644
--- a/tools/libxl/libxl_event.c
+++ b/tools/libxl/libxl_event.c
@@ -59,6 +59,9 @@  void libxl__egc_cleanup_1_baton(libxl__egc *egc)
     EGC_GC;
     libxl__poller *search, *wake=0;
 
+    if (CTX->poller_app->osevents_added)
+        baton_wake(egc, CTX->poller_app);
+
     LIBXL_LIST_FOREACH(search, &CTX->pollers_active, active_entry) {
         if (search == CTX->poller_app)
             /* This one is special.  We can't give it the baton. */