]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-master: anvil_client_query() delay calling callback on failures
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 13 Jun 2017 14:18:17 +0000 (17:18 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 14 Jun 2017 14:12:49 +0000 (17:12 +0300)
This fixes crash in lmtp on anvil connect failure where the callback wasn't
expecting to be called so early.

src/lib-master/anvil-client.c

index e1c7bd1fcd25b43090b84049f0a6abfdba2c39b1..5d34030b136b5d5fe0e21d6c35f545846902e6aa 100644 (file)
@@ -229,16 +229,19 @@ anvil_client_query(struct anvil_client *client, const char *query,
 {
        struct anvil_query *anvil_query;
 
-       if (anvil_client_send(client, query) < 0) {
-               callback(NULL, context);
-               return NULL;
-       }
-
        anvil_query = i_new(struct anvil_query, 1);
        anvil_query->callback = callback;
        anvil_query->context = context;
        aqueue_append(client->queries, &anvil_query);
-       if (client->to_query == NULL) {
+       if (anvil_client_send(client, query) < 0) {
+               /* connection failure. add a delayed failure callback.
+                  the caller may not expect the callback to be called
+                  immediately. */
+               if (client->to_query != NULL)
+                       timeout_remove(&client->to_query);
+               client->to_query =
+                       timeout_add_short(0, anvil_client_cancel_queries, client);
+       } else if (client->to_query == NULL) {
                client->to_query = timeout_add(ANVIL_QUERY_TIMEOUT_MSECS,
                                               anvil_client_timeout, client);
        }