Download raw body.
event_asr_dispatch: respect error from event_add
On Fri, 14 Jun 2024 21:55:02 +0100,
Kirill A. Korinsky <kirill@korins.ky> wrote:
>
> tech@,
>
> I noticed that event_asr_dispatch never checks the return of event_add,
> which can lead to a kind of deadlock when an application expects the
> callback to fire, but it doesn't fire because asr_run returned error, and it
> can't schedule the new attempt.
>
> Here is a suggested diff that sets ar_errno and ar_h_errno and fires the
> callback.
>
and here updated version of diff which setup all errno.
Thus, it also calls event_del but it returns non zero only when base is
missed, and it is impossible because eva->ev already used.
diff --git lib/libevent/event.c lib/libevent/event.c
index 26bc37dea76..d45604cc085 100644
--- lib/libevent/event.c
+++ lib/libevent/event.c
@@ -949,9 +949,18 @@ event_asr_dispatch(int fd __attribute__((__unused__)),
event_set(&eva->ev, ar.ar_fd,
ar.ar_cond == ASR_WANT_READ ? EV_READ : EV_WRITE,
event_asr_dispatch, eva);
+
tv.tv_sec = ar.ar_timeout / 1000;
tv.tv_usec = (ar.ar_timeout % 1000) * 1000;
- event_add(&eva->ev, &tv);
+
+ if (event_add(&eva->ev, &tv)) {
+ ar.ar_errno = errno;
+ ar.ar_h_errno = NETDB_INTERNAL;
+ ar.ar_gai_errno = EAI_SYSTEM;
+ ar.ar_rrset_errno = NETDB_INTERNAL;
+ eva->cb(&ar, eva->arg);
+ free(eva);
+ }
}
}
--
wbr, Kirill
event_asr_dispatch: respect error from event_add