diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-22 13:07:44 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-08-22 13:07:44 +0100 |
commit | 3f0f843468f2c7922141748b04faf7faf34dcf1d (patch) | |
tree | a2b11e9d636f82cf44c1484149089eeb96c1599e | |
parent | 28193d7f3fc7377388055ba9d6311747659f4303 (diff) | |
download | rspamd-3f0f843468f2c7922141748b04faf7faf34dcf1d.tar.gz rspamd-3f0f843468f2c7922141748b04faf7faf34dcf1d.zip |
[Feature] Implement address retry on connection failure
-rw-r--r-- | src/libserver/maps/map.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/src/libserver/maps/map.c b/src/libserver/maps/map.c index 712bdeaa8..c49896829 100644 --- a/src/libserver/maps/map.c +++ b/src/libserver/maps/map.c @@ -1223,21 +1223,23 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg) if (cbd->stage == http_map_http_conn && cbd->addrs->len > 0) { rspamd_ptr_array_shuffle (cbd->addrs); + gint idx = 0; /* * For the existing addr we can just select any address as we have * data available */ if (cbd->map->nelts > 0 && rspamd_random_double_fast () > 0.5) { /* Already shuffled, use whatever is the first */ - cbd->addr = (rspamd_inet_addr_t *) g_ptr_array_index (cbd->addrs, 0); + cbd->addr = (rspamd_inet_addr_t *) g_ptr_array_index (cbd->addrs, idx); } else { /* Always prefer IPv4 as IPv6 is almost all the time broken */ g_ptr_array_sort (cbd->addrs, rspamd_map_dns_address_sort_func); - cbd->addr = (rspamd_inet_addr_t *) g_ptr_array_index (cbd->addrs, 0); + cbd->addr = (rspamd_inet_addr_t *) g_ptr_array_index (cbd->addrs, idx); } - msg_debug_map ("open http connection to %s", +retry: + msg_debug_map ("try open http connection to %s", rspamd_inet_address_to_string_pretty (cbd->addr)); cbd->conn = rspamd_http_connection_new_client (NULL, NULL, @@ -1250,14 +1252,29 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg) write_http_request (cbd); } else { - cbd->periodic->errored = TRUE; - msg_err_map ("error reading %s(%s): " - "connection with http server terminated incorrectly: %s", - cbd->bk->uri, - cbd->addr ? rspamd_inet_address_to_string_pretty (cbd->addr) : "", - strerror (errno)); - - rspamd_map_process_periodic (cbd->periodic); + if (idx < cbd->addrs->len - 1) { + /* We can retry */ + idx++; + rspamd_inet_addr_t *prev_addr = cbd->addr; + cbd->addr = (rspamd_inet_addr_t *) g_ptr_array_index (cbd->addrs, idx); + msg_info_map ("cannot connect to %s to get data for %s: %s, retry with %s", + rspamd_inet_address_to_string_pretty (prev_addr), + cbd->bk->uri, + strerror (errno), + rspamd_inet_address_to_string_pretty (cbd->addr)); + goto retry; + } + else { + /* Nothing else left */ + cbd->periodic->errored = TRUE; + msg_err_map ("error reading %s(%s): " + "connection with http server terminated incorrectly: %s", + cbd->bk->uri, + cbd->addr ? rspamd_inet_address_to_string_pretty (cbd->addr) : "", + strerror (errno)); + + rspamd_map_process_periodic (cbd->periodic); + } } } |