custom thread mainloop: finish pending sources when removing

We sometimes set a custom per-thread mainloop because and then spin it
manually to fake a sync call on a thread using async calls. Primarily
this happens with the soup streaming calls. In this case, eventually
we finish the main loop iteration (because, say, the download is done)
so we stop iterating the mainloop and return from the fake sync code.

However, that might not necessarily be the only thing queued on the
main context. I ran into a situation where it seems like libsoup did
some call to a thread-pool during the async call, and the next time i
used soup aync everything froze. It looks like there is some threaded
soup service that returned a response on the old context, and since
that never got handled (since that context is now dead) it now doesn't
work.

To solve this situation we're now iterating the main context until
there are no pending sources before killing the main context.
This commit is contained in:
Alexander Larsson
2021-03-18 10:20:27 +01:00
committed by Alexander Larsson
parent 1b130c5cc3
commit adfa816cd4

View File

@@ -679,6 +679,10 @@ flatpak_main_context_pop_default_destroy (void *p)
if (main_context)
{
/* Ensure we don't leave some cleanup callbacks unhandled as we will never iterate this context again. */
while (g_main_context_pending (main_context))
g_main_context_iteration (main_context, TRUE);
g_main_context_pop_thread_default (main_context);
g_main_context_unref (main_context);
}