]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-client: Don't return "Dict server timeout" too early.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 26 Sep 2016 13:44:21 +0000 (16:44 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 26 Sep 2016 13:44:21 +0000 (16:44 +0300)
This could have happened when many dict commands were being run without
the timeout being reset in the middle.

src/lib-dict/dict-client.c

index f99bac318d75e1d18fec0515cdf2a261c9cb2610..311e5d7651ceb9c71990b516e0600c157b70bc70 100644 (file)
@@ -190,13 +190,29 @@ dict_cmd_callback_error(struct client_dict_cmd *cmd, const char *error,
 static void client_dict_input_timeout(struct client_dict *dict)
 {
        struct client_dict_cmd *const *cmds;
-       unsigned int count;
+       unsigned int i, count;
        const char *error;
+       int cmd_diff;
 
+       /* find the first expired non-background command */
        cmds = array_get(&dict->cmds, &count);
-       i_assert(count > 0);
+       for (i = 0; i < count; i++) {
+               if (cmds[i]->background)
+                       continue;
+               cmd_diff = timeval_diff_msecs(&ioloop_timeval, &cmds[i]->start_time);
+               if (cmd_diff < DICT_CLIENT_REQUEST_TIMEOUT_MSECS) {
+                       /* need to re-create this timeout. the currently-oldest
+                          command was added when another command was still
+                          running with an older timeout. */
+                       timeout_remove(&dict->to_requests);
+                       dict->to_requests =
+                               timeout_add(DICT_CLIENT_REQUEST_TIMEOUT_MSECS - cmd_diff,
+                                           client_dict_input_timeout, dict);
+               }
+               break;
+       }
+       i_assert(i < count); /* we can't have only background commands */
 
-       int cmd_diff = timeval_diff_msecs(&ioloop_timeval, &cmds[0]->start_time);
        (void)client_dict_reconnect(dict, t_strdup_printf(
                "Dict server timeout: %s "
                "(%u commands pending, oldest sent %u.%03u secs ago: %s)",