Start write threads after plugin initialization.
authorJan Andres <jan.andres@berenberg.de>
Wed, 21 Oct 2015 11:50:43 +0000 (13:50 +0200)
committerMarc Fournier <marc.fournier@camptocamp.com>
Sun, 8 Nov 2015 16:12:34 +0000 (17:12 +0100)
Some plugins such as "network" create own threads from within their
init callbacks which can then start submitting data to the queue
right away, even if the read threads haven't been started yet.

If write threads are started before plugin initialization, this can
result in a race where a plugin's write callback gets called before
that plugin's init callback has completed.

To fix this, delay starting the write threads until after all plugins
have been initialized.

src/plugin.c

index 97352c4..6d3d3c9 100644 (file)
@@ -1501,8 +1501,6 @@ void plugin_init_all (void)
                write_threads_num = 5;
        }
 
-       start_write_threads ((size_t) write_threads_num);
-
        if ((list_init == NULL) && (read_heap == NULL))
                return;
 
@@ -1538,6 +1536,8 @@ void plugin_init_all (void)
                le = le->next;
        }
 
+       start_write_threads ((size_t) write_threads_num);
+
        /* Start read-threads */
        if (read_heap != NULL)
        {