changeset 22419:55bd9d8ca7ce

push-notification: Switch to main ioloop while calling drivers' deinit/cleanup callbacks Continues a44595f7b1afc7ccbd8653598753b32899d01c76 to other functions. For example the OX backend would call http_client_wait(), which would move the I/Os and timeouts to the current ioloop, which might not be main_ioloop always. When that ioloop gets destroyed, I/O and timeout leaks are logged and eventually the process crashes when calling http_client_deinit() in cleanup() (this would happen later for another mail_user).
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 09 Aug 2017 13:23:36 +0300
parents cbd8f0cb2ce4
children 7ae7c3c159d1
files src/plugins/push-notification/push-notification-plugin.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/push-notification/push-notification-plugin.c	Wed Jul 26 12:53:16 2017 +0300
+++ b/src/plugins/push-notification/push-notification-plugin.c	Wed Aug 09 13:23:36 2017 +0300
@@ -275,6 +275,11 @@
     struct push_notification_user *puser = PUSH_NOTIFICATION_USER_CONTEXT(user);
     struct push_notification_driver_list *dlist = puser->driverlist;
     struct push_notification_driver_user **duser;
+    struct ioloop *prev_ioloop = current_ioloop;
+
+    /* Make sure we're in the main ioloop, so if the deinit/cleanup moves any
+       I/Os or timeouts they won't get moved to some temporary ioloop. */
+    io_loop_set_current(main_ioloop);
 
     array_foreach_modifiable(&dlist->drivers, duser) {
         if ((*duser)->driver->v.deinit != NULL) {
@@ -285,6 +290,8 @@
             (*duser)->driver->v.cleanup();
         }
     }
+    io_loop_set_current(prev_ioloop);
+
     puser->module_ctx.super.deinit(user);
 }