From 3634fff4dd42857c1a270746c4a260771a9c8777 Mon Sep 17 00:00:00 2001 From: Robert Groenenberg Date: Mon, 20 Jun 2016 18:39:15 +0200 Subject: [PATCH] Return call_reporting info in case of timeout, so that we can see which server did not respond. --- src/stub.c | 7 +++++-- src/types-internal.h | 3 ++- src/util-internal.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/stub.c b/src/stub.c index 2962b3fb..488da2fd 100644 --- a/src/stub.c +++ b/src/stub.c @@ -91,6 +91,7 @@ static int upstream_connect(getdns_upstream *upstream, static int fallback_on_write(getdns_network_req *netreq); static void stub_timeout_cb(void *userarg); +static uint64_t _getdns_get_time_as_uintt64() /*****************************/ /* General utility functions */ /*****************************/ @@ -564,9 +565,11 @@ stub_timeout_cb(void *userarg) stub_next_upstream(netreq); stub_cleanup(netreq); if (netreq->fd >= 0) close(netreq->fd); - if (netreq->owner->user_callback) + if (netreq->owner->user_callback) { + netreq->state = NET_REQ_TIMED_OUT; + netreq->debug_end_time = _getdns_get_time_as_uintt64(); (void) _getdns_context_request_timed_out(netreq->owner); - else { + } else { netreq->state = NET_REQ_FINISHED; _getdns_check_dns_req_complete(netreq->owner); } diff --git a/src/types-internal.h b/src/types-internal.h index f63fde13..a43bd8f6 100644 --- a/src/types-internal.h +++ b/src/types-internal.h @@ -157,7 +157,8 @@ typedef enum network_req_state_enum NET_REQ_NOT_SENT, NET_REQ_IN_FLIGHT, NET_REQ_FINISHED, - NET_REQ_CANCELED + NET_REQ_CANCELED, + NET_REQ_TIMED_OUT } network_req_state; diff --git a/src/util-internal.c b/src/util-internal.c index ca04c7f5..f3295ec4 100644 --- a/src/util-internal.c +++ b/src/util-internal.c @@ -1189,6 +1189,25 @@ _getdns_create_getdns_response(getdns_dns_req *completed_request) netreq->response_len, netreq->response)) goto error; } + if (!nreplies && call_reporting) { + for ( netreq_p = completed_request->netreqs + ; (netreq = *netreq_p) ; netreq_p++) { + /* Add call_reporting info for timed out request */ + if (netreq->state == NET_REQ_TIMED_OUT) { + if (!(netreq_debug = + _getdns_create_call_reporting_dict(context,netreq))) + goto error; + + if (_getdns_list_append_this_dict( + call_reporting, netreq_debug)) { + + getdns_dict_destroy(netreq_debug); + goto error; + } + } + } + } + if (_getdns_dict_set_this_list(result, "replies_tree", replies_tree)) goto error; replies_tree = NULL;