Account for callbacks fired during scheduling

This commit is contained in:
Willem Toorop 2016-04-21 15:16:38 +02:00
parent 0bd4026898
commit 15271d0438
5 changed files with 62 additions and 18 deletions

View File

@ -3181,7 +3181,7 @@ static void check_chain_complete(chain_head *chain)
&& !dnsreq->avoid_dnssec_roadblocks && !dnsreq->avoid_dnssec_roadblocks
&& dnsreq->netreqs[0]->dnssec_status == GETDNS_DNSSEC_BOGUS) { && dnsreq->netreqs[0]->dnssec_status == GETDNS_DNSSEC_BOGUS) {
getdns_return_t r = GETDNS_RETURN_GOOD; int r = GETDNS_RETURN_GOOD;
getdns_network_req **netreq_p, *netreq; getdns_network_req **netreq_p, *netreq;
dnsreq->avoid_dnssec_roadblocks = 1; dnsreq->avoid_dnssec_roadblocks = 1;

View File

@ -161,7 +161,7 @@ void
_getdns_check_dns_req_complete(getdns_dns_req *dns_req) _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
{ {
getdns_network_req **netreq_p, *netreq; getdns_network_req **netreq_p, *netreq;
int results_found = 0; int results_found = 0, r;
for (netreq_p = dns_req->netreqs; (netreq = *netreq_p); netreq_p++) for (netreq_p = dns_req->netreqs; (netreq = *netreq_p); netreq_p++)
if (netreq->state != NET_REQ_FINISHED && if (netreq->state != NET_REQ_FINISHED &&
@ -198,8 +198,11 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
; (netreq = *netreq_p) ; (netreq = *netreq_p)
; netreq_p++ ) { ; netreq_p++ ) {
_getdns_netreq_reinit(netreq); _getdns_netreq_reinit(netreq);
if (_getdns_submit_netreq(netreq)) if ((r = _getdns_submit_netreq(netreq))) {
if (r == DNS_REQ_FINISHED)
return;
netreq->state = NET_REQ_FINISHED; netreq->state = NET_REQ_FINISHED;
}
} }
_getdns_check_dns_req_complete(dns_req); _getdns_check_dns_req_complete(dns_req);
return; return;
@ -233,8 +236,11 @@ _getdns_check_dns_req_complete(getdns_dns_req *dns_req)
; (netreq = *netreq_p) ; (netreq = *netreq_p)
; netreq_p++ ) { ; netreq_p++ ) {
_getdns_netreq_reinit(netreq); _getdns_netreq_reinit(netreq);
if (_getdns_submit_netreq(netreq)) if ((r = _getdns_submit_netreq(netreq))) {
if (r == DNS_REQ_FINISHED)
return;
netreq->state = NET_REQ_FINISHED; netreq->state = NET_REQ_FINISHED;
}
} }
_getdns_check_dns_req_complete(dns_req); _getdns_check_dns_req_complete(dns_req);
return; return;
@ -312,13 +318,16 @@ ub_resolve_callback(void* arg, int err, struct ub_result* ub_res)
#endif #endif
getdns_return_t int
_getdns_submit_netreq(getdns_network_req *netreq) _getdns_submit_netreq(getdns_network_req *netreq)
{ {
getdns_return_t r; getdns_return_t r;
getdns_dns_req *dns_req = netreq->owner; getdns_dns_req *dns_req = netreq->owner;
char name[1024]; char name[1024];
int dnsreq_freed = 0;
#ifdef HAVE_LIBUNBOUND
int ub_resolve_r;
#endif
#ifdef STUB_NATIVE_DNSSEC #ifdef STUB_NATIVE_DNSSEC
# ifdef DNSSEC_ROADBLOCK_AVOIDANCE # ifdef DNSSEC_ROADBLOCK_AVOIDANCE
@ -351,24 +360,34 @@ _getdns_submit_netreq(getdns_network_req *netreq)
dns_req->name_len, name, sizeof(name)); dns_req->name_len, name, sizeof(name));
#ifdef HAVE_LIBUNBOUND #ifdef HAVE_LIBUNBOUND
dns_req->freed = &dnsreq_freed;
#ifdef HAVE_UNBOUND_EVENT_API #ifdef HAVE_UNBOUND_EVENT_API
if (_getdns_ub_loop_enabled(&dns_req->context->ub_loop)) if (_getdns_ub_loop_enabled(&dns_req->context->ub_loop))
return ub_resolve_event(dns_req->context->unbound_ctx, ub_resolve_r = ub_resolve_event(dns_req->context->unbound_ctx,
name, netreq->request_type, netreq->owner->request_class, name, netreq->request_type, netreq->owner->request_class,
netreq, ub_resolve_event_callback, &(netreq->unbound_id)) ? netreq, ub_resolve_event_callback, &(netreq->unbound_id)) ?
GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD; GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD;
else else
#endif #endif
return ub_resolve_async(dns_req->context->unbound_ctx, ub_resolve_r = ub_resolve_async(dns_req->context->unbound_ctx,
name, netreq->request_type, netreq->owner->request_class, name, netreq->request_type, netreq->owner->request_class,
netreq, ub_resolve_callback, &(netreq->unbound_id)) ? netreq, ub_resolve_callback, &(netreq->unbound_id)) ?
GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD; GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD;
if (dnsreq_freed)
return DNS_REQ_FINISHED;
dns_req->freed = NULL;
return ub_resolve_r ? GETDNS_RETURN_GENERIC_ERROR : GETDNS_RETURN_GOOD;
#else #else
return GETDNS_RETURN_NOT_IMPLEMENTED; return GETDNS_RETURN_NOT_IMPLEMENTED;
#endif #endif
} }
/* Submit with stub resolver */ /* Submit with stub resolver */
return _getdns_submit_stub_request(netreq); dns_req->freed = &dnsreq_freed;
r = _getdns_submit_stub_request(netreq);
if (dnsreq_freed)
return DNS_REQ_FINISHED;
dns_req->freed = NULL;
return r;
} }
@ -456,7 +475,7 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
void *userarg, getdns_network_req **return_netreq_p, void *userarg, getdns_network_req **return_netreq_p,
getdns_callback_t callbackfn, internal_cb_t internal_cb, int usenamespaces) getdns_callback_t callbackfn, internal_cb_t internal_cb, int usenamespaces)
{ {
getdns_return_t r = GETDNS_RETURN_GOOD; int r = GETDNS_RETURN_GOOD;
getdns_network_req *netreq, **netreq_p; getdns_network_req *netreq, **netreq_p;
getdns_dns_req *req; getdns_dns_req *req;
getdns_dict *localnames_response; getdns_dict *localnames_response;
@ -495,8 +514,16 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
/* issue all network requests */ /* issue all network requests */
for ( netreq_p = req->netreqs for ( netreq_p = req->netreqs
; !r && (netreq = *netreq_p) ; !r && (netreq = *netreq_p)
; netreq_p++) ; netreq_p++) {
r = _getdns_submit_netreq(netreq); if ((r = _getdns_submit_netreq(netreq))) {
if (r == DNS_REQ_FINISHED) {
if (return_netreq_p)
*return_netreq_p = NULL;
return GETDNS_RETURN_GOOD;
}
netreq->state = NET_REQ_FINISHED;
}
}
else for (i = 0; i < context->namespace_count; i++) { else for (i = 0; i < context->namespace_count; i++) {
if (context->namespaces[i] == GETDNS_NAMESPACE_LOCALNAMES) { if (context->namespaces[i] == GETDNS_NAMESPACE_LOCALNAMES) {
@ -517,14 +544,21 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
r = GETDNS_RETURN_GOOD; r = GETDNS_RETURN_GOOD;
for ( netreq_p = req->netreqs for ( netreq_p = req->netreqs
; !r && (netreq = *netreq_p) ; !r && (netreq = *netreq_p)
; netreq_p++) ; netreq_p++) {
r = _getdns_submit_netreq(netreq); if ((r = _getdns_submit_netreq(netreq))) {
if (r == DNS_REQ_FINISHED) {
if (return_netreq_p)
*return_netreq_p = NULL;
return GETDNS_RETURN_GOOD;
}
netreq->state = NET_REQ_FINISHED;
}
}
break; break;
} else } else
r = GETDNS_RETURN_BAD_CONTEXT; r = GETDNS_RETURN_BAD_CONTEXT;
} }
if (r > 0) { /* i.e. r != GETDNS_RETURN_GOOD && r != DNS_REQ_FINISHED */
if (r != 0) {
/* clean up the request */ /* clean up the request */
_getdns_context_clear_outbound_request(req); _getdns_context_clear_outbound_request(req);
_getdns_dns_req_free(req); _getdns_dns_req_free(req);

View File

@ -42,9 +42,11 @@
/* private inner helper used by sync and async */ /* private inner helper used by sync and async */
#define DNS_REQ_FINISHED -1
void _getdns_call_user_callback(getdns_dns_req *, getdns_dict *); void _getdns_call_user_callback(getdns_dns_req *, getdns_dict *);
void _getdns_check_dns_req_complete(getdns_dns_req *dns_req); void _getdns_check_dns_req_complete(getdns_dns_req *dns_req);
getdns_return_t _getdns_submit_netreq(getdns_network_req *netreq); int _getdns_submit_netreq(getdns_network_req *netreq);
getdns_return_t getdns_return_t

View File

@ -640,7 +640,8 @@ _getdns_dns_req_free(getdns_dns_req * req)
req->loop->vmt->clear(req->loop, &req->timeout); req->loop->vmt->clear(req->loop, &req->timeout);
req->timeout.timeout_cb = NULL; req->timeout.timeout_cb = NULL;
} }
if (req->freed)
*req->freed = 1;
GETDNS_FREE(req->my_mf, req); GETDNS_FREE(req->my_mf, req);
} }
@ -901,6 +902,7 @@ _getdns_dns_req_new(getdns_context *context, getdns_eventloop *loop,
result->upstreams->referenced++; result->upstreams->referenced++;
result->finished_next = NULL; result->finished_next = NULL;
result->freed = NULL;
network_req_init(result->netreqs[0], result, network_req_init(result->netreqs[0], result,
request_type, dnssec_extension_set, with_opt, request_type, dnssec_extension_set, with_opt,

View File

@ -304,6 +304,12 @@ typedef struct getdns_dns_req {
int dnssec_ok_checking_disabled; int dnssec_ok_checking_disabled;
int is_sync_request; int is_sync_request;
/* Integer pointed to by pointer will be set to 1 (if set),
* before the request is freed.
* To be used by _getdns_submit_netreq only!
*/
int *freed;
/* internally scheduled request */ /* internally scheduled request */
internal_cb_t internal_cb; internal_cb_t internal_cb;