changeset 21652:e04d881da1fb

cassandra: Don't use i_error() from non-main thread 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 21 Feb 2017 11:55:55 +0200
parents 79d9124f8c8b
children 8f374e21547a
files src/lib-sql/driver-cassandra.c
diffstat 1 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-sql/driver-cassandra.c	Tue Feb 21 13:08:59 2017 +0200
+++ b/src/lib-sql/driver-cassandra.c	Tue Feb 21 11:55:55 2017 +0200
@@ -266,9 +266,16 @@
 	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)