mirror of https://github.com/getdnsapi/getdns.git
Bugfix in handling UDP backing off
This commit is contained in:
parent
fa99b206e8
commit
5d12545391
|
@ -938,7 +938,7 @@ upstream_init(getdns_upstream *upstream,
|
||||||
upstream->keepalive_shutdown = 0;
|
upstream->keepalive_shutdown = 0;
|
||||||
upstream->keepalive_timeout = 0;
|
upstream->keepalive_timeout = 0;
|
||||||
/* How is this upstream doing on UDP? */
|
/* How is this upstream doing on UDP? */
|
||||||
upstream->to_retry = 2;
|
upstream->to_retry = 1;
|
||||||
upstream->back_off = 1;
|
upstream->back_off = 1;
|
||||||
upstream->udp_responses = 0;
|
upstream->udp_responses = 0;
|
||||||
upstream->udp_timeouts = 0;
|
upstream->udp_timeouts = 0;
|
||||||
|
|
|
@ -131,9 +131,32 @@ typedef struct getdns_upstream {
|
||||||
char addr_str[INET6_ADDRSTRLEN];
|
char addr_str[INET6_ADDRSTRLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* How is this upstream doing over UDP? */
|
/**
|
||||||
int to_retry;
|
* How is this upstream doing over UDP?
|
||||||
int back_off;
|
*
|
||||||
|
* to_retry = 1, back_off = 1, in context.c:upstream_init()
|
||||||
|
*
|
||||||
|
* When querying over UDP, first a upstream is selected which to_retry
|
||||||
|
* value > 0 in stub.c:upstream_select().
|
||||||
|
*
|
||||||
|
* Every time a udp request times out, to_retry is decreased, and if
|
||||||
|
* it reaches 0, it is set to minus back_off in
|
||||||
|
* stub.c:stub_next_upstream().
|
||||||
|
*
|
||||||
|
* to_retry will become > 0 again. because each time an upstream is
|
||||||
|
* selected for a UDP query in stub.c:upstream_select(), all to_retry
|
||||||
|
* counters <= 0 are incremented.
|
||||||
|
*
|
||||||
|
* On continuous failure, the stubs are less likely to be reselected,
|
||||||
|
* because each time to_retry is set to minus back_off, in
|
||||||
|
* stub.c:stub_next_upstream(), the back_off value is doubled.
|
||||||
|
*
|
||||||
|
* Finally, if all upstreams are failing, the upstreams with the
|
||||||
|
* smallest back_off value will be selected, and the back_off value
|
||||||
|
* decremented by one.
|
||||||
|
*/
|
||||||
|
int to_retry; /* (initialized to 1) */
|
||||||
|
int back_off; /* (initialized to 1) */
|
||||||
size_t udp_responses;
|
size_t udp_responses;
|
||||||
size_t udp_timeouts;
|
size_t udp_timeouts;
|
||||||
|
|
||||||
|
|
36
src/stub.c
36
src/stub.c
|
@ -600,10 +600,10 @@ stub_timeout_cb(void *userarg)
|
||||||
#endif
|
#endif
|
||||||
netreq->upstream->udp_timeouts++;
|
netreq->upstream->udp_timeouts++;
|
||||||
#if defined(DAEMON_DEBUG) && DAEMON_DEBUG
|
#if defined(DAEMON_DEBUG) && DAEMON_DEBUG
|
||||||
if (netreq->upstream->udp_timeouts % 100 == 0)
|
if (netreq->upstream->udp_timeouts % 100 == 0)
|
||||||
DEBUG_DAEMON("%s %-40s : Upstream stats: Transport=UDP - Resp=%d,Timeouts=%d\n",
|
DEBUG_DAEMON("%s %-40s : Upstream stats: Transport=UDP - Resp=%d,Timeouts=%d\n",
|
||||||
STUB_DEBUG_DAEMON, netreq->upstream->addr_str,
|
STUB_DEBUG_DAEMON, netreq->upstream->addr_str,
|
||||||
(int)netreq->upstream->udp_responses, (int)netreq->upstream->udp_timeouts);
|
(int)netreq->upstream->udp_responses, (int)netreq->upstream->udp_timeouts);
|
||||||
#endif
|
#endif
|
||||||
stub_next_upstream(netreq);
|
stub_next_upstream(netreq);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1329,6 +1329,7 @@ _getdns_get_time_as_uintt64() {
|
||||||
/* UDP callback functions */
|
/* UDP callback functions */
|
||||||
/**************************/
|
/**************************/
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stub_udp_read_cb(void *userarg)
|
stub_udp_read_cb(void *userarg)
|
||||||
{
|
{
|
||||||
|
@ -1348,8 +1349,28 @@ stub_udp_read_cb(void *userarg)
|
||||||
*/
|
*/
|
||||||
0, NULL, NULL);
|
0, NULL, NULL);
|
||||||
if (read == -1 && _getdns_EWOULDBLOCK)
|
if (read == -1 && _getdns_EWOULDBLOCK)
|
||||||
return;
|
return; /* Try again later */
|
||||||
|
|
||||||
|
if (read == -1) {
|
||||||
|
DEBUG_STUB("%s %-35s: MSG: %p error while reading from socket:"
|
||||||
|
" %s\n", STUB_DEBUG_READ, __FUNC__, (void*)netreq
|
||||||
|
, strerror(errno));
|
||||||
|
|
||||||
|
stub_cleanup(netreq);
|
||||||
|
_getdns_netreq_change_state(netreq, NET_REQ_ERRORED);
|
||||||
|
/* Handle upstream*/
|
||||||
|
if (netreq->fd >= 0) {
|
||||||
|
#ifdef USE_WINSOCK
|
||||||
|
closesocket(netreq->fd);
|
||||||
|
#else
|
||||||
|
close(netreq->fd);
|
||||||
|
#endif
|
||||||
|
stub_next_upstream(netreq);
|
||||||
|
}
|
||||||
|
netreq->debug_end_time = _getdns_get_time_as_uintt64();
|
||||||
|
_getdns_check_dns_req_complete(netreq->owner);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (read < GLDNS_HEADER_SIZE)
|
if (read < GLDNS_HEADER_SIZE)
|
||||||
return; /* Not DNS */
|
return; /* Not DNS */
|
||||||
|
|
||||||
|
@ -1871,9 +1892,10 @@ upstream_select(getdns_network_req *netreq)
|
||||||
upstream->back_off)
|
upstream->back_off)
|
||||||
upstream = &upstreams->upstreams[i];
|
upstream = &upstreams->upstreams[i];
|
||||||
|
|
||||||
upstream->back_off++;
|
if (upstream->back_off > 1)
|
||||||
|
upstream->back_off--;
|
||||||
upstream->to_retry = 1;
|
upstream->to_retry = 1;
|
||||||
upstreams->current_udp = (upstream - upstreams->upstreams) / GETDNS_UPSTREAM_TRANSPORTS;
|
upstreams->current_udp = upstream - upstreams->upstreams;
|
||||||
return upstream;
|
return upstream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue