From 5e1575dabc5de48e1007cd195ca50edb0cf2c7a7 Mon Sep 17 00:00:00 2001 From: Sara Dickinson Date: Sat, 2 Jul 2016 16:20:08 +0100 Subject: [PATCH] Correct the logic for upstream back off --- src/context.c | 9 +++++---- src/stub.c | 4 ++-- src/types-internal.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/context.c b/src/context.c index 529bb19c..495217f4 100644 --- a/src/context.c +++ b/src/context.c @@ -696,11 +696,12 @@ _getdns_upstream_shutdown(getdns_upstream *upstream) use the same basis if we simply can't get TCP service either.*/ /* [TLS1]TODO: This arbitrary logic at the moment - review and improve!*/ - if (upstream->conn_setup_failed >= GETDNS_MAX_CONN_FAILS || - (upstream->conn_shutdowns >= GETDNS_MAX_CONN_FAILS*GETDNS_CONN_FAIL_MULT + if (upstream->conn_setup_failed >= GETDNS_CONN_ATTEMPTS || + (upstream->conn_shutdowns >= GETDNS_CONN_ATTEMPTS*GETDNS_TRANSPORT_FAIL_MULT && upstream->total_responses == 0) || - (upstream->total_timeouts > 0 && - upstream->total_responses*GETDNS_MAX_CONN_FAILS == 0)) + (upstream->conn_completed >= GETDNS_CONN_ATTEMPTS && + upstream->total_responses == 0 && + upstream->total_timeouts > GETDNS_TRANSPORT_FAIL_MULT)) upstream->conn_state = GETDNS_CONN_BACKOFF; // Reset per connection counters upstream->queries_sent = 0; diff --git a/src/stub.c b/src/stub.c index 90a8c935..efd293f8 100644 --- a/src/stub.c +++ b/src/stub.c @@ -1542,7 +1542,7 @@ upstream_working_ok(getdns_upstream *upstream) { /* [TLS1]TODO: This arbitrary logic at the moment - review and improve!*/ return (upstream->responses_timeouts > - upstream->responses_received*GETDNS_MAX_CONN_FAILS ? 0 : 1); + upstream->responses_received*GETDNS_CONN_ATTEMPTS ? 0 : 1); } static int @@ -1564,7 +1564,7 @@ upstream_stats(getdns_upstream *upstream) { /* [TLS1]TODO: This arbitrary logic at the moment - review and improve!*/ return (upstream->total_responses - upstream->total_timeouts - - upstream->conn_shutdowns*GETDNS_CONN_FAIL_MULT); + - upstream->conn_shutdowns*GETDNS_TRANSPORT_FAIL_MULT); } static int diff --git a/src/types-internal.h b/src/types-internal.h index f6e58619..f6c3cf5b 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -120,8 +120,8 @@ struct getdns_upstream; #define GETDNS_TRANSPORTS_MAX 3 #define GETDNS_UPSTREAM_TRANSPORTS 2 -#define GETDNS_MAX_CONN_FAILS 2 -#define GETDNS_CONN_FAIL_MULT 5 +#define GETDNS_CONN_ATTEMPTS 2 +#define GETDNS_TRANSPORT_FAIL_MULT 5 /* declarations */