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

Re: [Libevent-users] Re: libevent-2.0.8-rc/evdns.c:2672: Assertion (req)->handle && (req)->handle->current_req == (req) failed in evdns_cancel_request



On Wed, Nov 3, 2010 at 7:41 AM, Denis Bilenko <denis.bilenko@xxxxxxxxx> wrote:
> So what happens here, is that eventually reply_handle is called, which calls
>
> reply_schedule_callback(req, ttl, 0, reply); in evdns.c:872
> and then
> request_finished(req, &REQ_HEAD(req->base, req->trans_id), 1); in evdns.c:876
> which calls mm_free(req->handle)
>
> When I call cancel I pass this freed handle to evdns_cancel_request
> and that causes crash.
>
> So the problem here is that the evdns_request structure is freed
> before the user's callback is called and there's no way for the client
> code to know when it's OK to cancel the request.
>
> I might be missing something, but why go through
> reply_schedule_callback at all? Why not call the user's callback
> immediately and avoid extra step which makes cancel() unsafe?

Locking.  When we hit the point where we need to schedule a callback
(or call it directly) we're pretty deep in the guts of the dns code,
and we hold the lock on the evdns base.  We can't trivially drop the
lock before calling the user callback, but holding it while invoking
the user callback was an invitation for deadlock.

Probably the right answer here is to add a reference count to the
request, and not actually free it until the reference count hits zero.

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