]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
director: Don't block too long when sending users during director handshake
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 5 Nov 2017 23:30:13 +0000 (01:30 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 7 Nov 2017 19:24:51 +0000 (21:24 +0200)
All the other work is blocked while the users are being sent.

src/director/director-connection.c

index a89cc52d19ab7242068119edad2f58d541116d92..1f7b7052c094d2caaa732891f08e28c4aad58e5c 100644 (file)
@@ -82,6 +82,9 @@
    notification and reset the last_sync_seq */
 #define DIRECTOR_SYNC_STALE_TIMESTAMP_RESET_SECS (60*2)
 #define DIRECTOR_MAX_CLOCK_DIFF_WARN_SECS 1
+/* How many USER entries to send during handshake before going back to ioloop
+   to see if there's other work to be done as well. */
+#define DIRECTOR_HANDSHAKE_MAX_USERS_SENT_PER_FLUSH 10000
 
 #if DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS <= DIRECTOR_CONNECTION_PING_TIMEOUT_MSECS
 #  error DIRECTOR_CONNECTION_DONE_TIMEOUT_MSECS is too low
@@ -1984,6 +1987,7 @@ static int director_connection_send_users(struct director_connection *conn)
        struct user *user;
        string_t *str = t_str_new(128);
        char dec_buf[MAX_INT_STRLEN];
+       unsigned int sent_count = 0;
        int ret;
 
        i_assert(conn->version_received);
@@ -2000,6 +2004,11 @@ static int director_connection_send_users(struct director_connection *conn)
                        str_append(str, "\tw");
                str_append_c(str, '\n');
                director_connection_send(conn, str_c(str));
+               if (++sent_count >= DIRECTOR_HANDSHAKE_MAX_USERS_SENT_PER_FLUSH) {
+                       /* Don't send too much at once to avoid hangs */
+                       timeout_reset(conn->to_ping);
+                       return 0;
+               }
 
                if (o_stream_get_buffer_used_size(conn->output) >= OUTBUF_FLUSH_THRESHOLD) {
                        if ((ret = o_stream_flush(conn->output)) <= 0) {