[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] evdns_cancel_request may not fully cancel



On Fri, Aug 8, 2014 at 9:53 PM, Erik Fears <strtok@xxxxxxxxxx> wrote:
> Hello,
>
> I've run into an issue in my codebase where it appears evdns is calling
> a callback on a request that I've canceled.
>
> This is an issue for me, because once I call evdns_cancel_request, I've
> also freed my own context associated with the request (i.e. the
> void* passed back by libevent to the callback).
>
> If the result was always DNS_ERR_CANCEL on a cancelled request,
> this wouldn't be a problem, because I could abort. It seems that in some
> cases the result could be DNS_ERR_NONE if the callback was
> already pending
>
>
> I believe this code may be to blame?
>
> void
> evdns_cancel_request(struct evdns_base *base, struct evdns_request *handle)
> {
>         ...
>
> EVDNS_LOCK(base);
> if (handle->pending_cb) {
> EVDNS_UNLOCK(base);
> return;
> }
>
>         ...
> }
>

Hm.  By the time that pending_cb is set, the deferred_cb for the evdns
request is already scheduled and ready to run.  Maybe
evdns_cancel_request needs to cancel the deferred_cb object if
possible by invoking evend_deferred_cb_cancel on it..  (Even so, there
is going to be an issue for multithreaded programs, where the callback
might be running at the same time you're trying to cancel it.)

Possibly evdns_cancel_request needs to return a value to indicate
whether cancelling the request succeeded.

-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.