]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Select a different upstream on last retransmit
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Dec 2019 10:49:22 +0000 (10:49 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 10 Dec 2019 10:49:22 +0000 (10:49 +0000)
Issue: #3182

src/rspamd_proxy.c

index 6cc2e592def652625a12170cad0af2929f55c155..2a0cadbf10a753b4e91ae731a55f69944f26b78d 100644 (file)
@@ -1872,8 +1872,25 @@ retry:
                        goto err;
                }
 
-               session->master_conn->up = rspamd_upstream_get (backend->u,
-                               RSPAMD_UPSTREAM_ROUND_ROBIN, NULL, 0);
+               /* Provide hash key if hashing based on source address is desired */
+               guint hash_len;
+               gpointer hash_key = rspamd_inet_address_get_hash_key (session->client_addr,
+                               &hash_len);
+
+               if (session->ctx->max_retries > 1 &&
+                       session->retries == session->ctx->max_retries) {
+
+                       session->master_conn->up = rspamd_upstream_get_except (backend->u,
+                                       session->master_conn->up,
+                                       RSPAMD_UPSTREAM_ROUND_ROBIN,
+                                       hash_key, hash_len);
+               }
+               else {
+                       session->master_conn->up = rspamd_upstream_get (backend->u,
+                                       RSPAMD_UPSTREAM_ROUND_ROBIN,
+                                       hash_key, hash_len);
+               }
+
                session->master_conn->timeout = backend->timeout;
 
                if (session->master_conn->up == NULL) {