]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
cassandra: Don't use i_error() from non-main thread
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Feb 2017 09:55:55 +0000 (11:55 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 21 Feb 2017 12:57:07 +0000 (14:57 +0200)
It will only cause crashes. This was done only if the internal
communication pipe couldn't be written to, which was pretty unlikely
to happen.

src/lib-sql/driver-cassandra.c

index b158351f9c2d3758e99844020a36f720c4f28300..d6c6fb821ce0ad6f5e0300145c9abd3b242e7a45 100644 (file)
@@ -266,9 +266,16 @@ static void driver_cassandra_future_callback(CassFuture *future ATTR_UNUSED,
        struct cassandra_callback *cb = context;
 
        /* this isn't the main thread - communicate with main thread by
-          writing the callback id to the pipe */
-       if (write_full(cb->db->fd_pipe[1], &cb->id, sizeof(cb->id)) < 0)
-               i_error("cassandra: write(pipe) failed: %m");
+          writing the callback id to the pipe. note that we must not use
+          almost any dovecot functions here because most of them are using
+          data-stack, which isn't thread-safe. especially don't use
+          i_error() here. */
+       if (write_full(cb->db->fd_pipe[1], &cb->id, sizeof(cb->id)) < 0) {
+               const char *str = t_strdup_printf(
+                       "cassandra: write(pipe) failed: %s\n",
+                       strerror(errno));
+               (void)write_full(STDERR_FILENO, str, strlen(str));
+       }
 }
 
 static void cassandra_callback_run(struct cassandra_callback *cb)