libunbound: setting a deadline/timeout for ub_resolve

Alex Zorin ub-users at id-rsa.pub
Fri Jun 8 07:58:11 UTC 2018


Thanks Wouter, that very helpful.

On Fri, Jun 8, 2018, at 3:56 PM, W.C.A. Wijngaards via Unbound-users wrote:
> Hi Alex,
> 
> On 08/06/18 01:57, Alex Zorin via Unbound-users wrote:
> > Hello,
> > 
> > I'm using libunbound to perform iterative DNS lookups for a diagnostic service: github.com/letsdebug/letsdebug .
> > 
> > One of the problems I have is when one or more of a domain's authoritative nameservers are timing out, ub_resolve takes an incredibly long time to give up, something like ~10 minutes when the ub_ctx is configured with these options:
> 
> If a timeout is needed, set a timeout.  So the code calling libunbound
> sets the timeout it wants.  And then cancels or ignores the return value
> of the lookup.
> 
> For example, use ub_resolve_async(), and then ub_fd(ctx) put that file
> descriptor in select or poll, with a timeout that you want to select or
> poll. So, sketching code that would look like this:
> ub_resolve_async(ctx, name, type, class, 0, funcwhendone, &async_id);
> struct pollfd fds[1];
> fds[0].fd = ub_fd(ctx);
> fds[0].events = POLLIN;
> fds[0].revents = 0;
> int r = poll(fds, 1, 180 * 1000);
> if(r == 0) /* timeout */
> else if(r == -1) /* poll has a system error */
> else ub_process(ctx); /* calls funcwhendone */
> 
> At timeout you could call ub_cancel(ctx, async_id) or just ignore the
> result when funcwhendone gets called (eventually).  Or delete the
> context, you say you only use it once, this also removes that callback.
> 
> Best regards, Wouter
> 
> > 
> >     https://github.com/letsdebug/letsdebug/blob/e56f10a5741445645c44a6d6683b9f085f657999/dns_util.go#L84-L116
> > 
> > I've tried to grok the meaning of https://www.unbound.net/documentation/info_timeout.html but I'm not seeing the solution after some weeks of pondering the problem..
> >  
> > Ideally I would like to place a deadline of something like 180 seconds on the ub_resolve operation. I am using a fresh ub_ctx for each lookup, which is done to avoid sharing any resolver state between lookups.
> > 
> > Do you have any further guidance on the ability to restrict ub_resolve's runtime?
> > 
> > Thanks!
> > Alex
> > 
> 
> 
> Email had 1 attachment:
> + signature.asc
>   1k (application/pgp-signature)



More information about the Unbound-users mailing list