Hello,
Under the conditions where there are two or more handlers registered for a single fd in the multiplexer and one of the handlers removes all the fd's callbacks and other callbacks for that fd should have been invoked in the same event-dispath iteration, there is an invocation of a nil callback in event-dispatch. To the best of my knowledge, this patch below fixes it.
Thank you.
-pete
diff --git a/src/multiplex/event-loop.lisp b/src/multiplex/event-loop.lisp index 35879fd..4afba32 100644 --- a/src/multiplex/event-loop.lisp +++ b/src/multiplex/event-loop.lisp @@ -306,7 +306,8 @@ within the extent of BODY. Closes VAR." (setf expired-events nil) (setf (values eventsp deletion-list) (dispatch-fd-events-once event-base poll-timeout now)) - (%remove-handlers event-base deletion-list) + (unless (equal '(nil nil) deletion-list) + (%remove-handlers event-base deletion-list)) (when (expire-pending-timers fd-timers now) (setf eventsp t)) (dispatch-fd-timeouts expired-events) (when (expire-pending-timers timers now) (setf eventsp t)) @@ -352,13 +353,14 @@ within the extent of BODY. Closes VAR."
(defun %dispatch-event (fd-entry event-type errorp now) (let ((ev (fd-entry-handler fd-entry event-type))) - (funcall (fd-handler-callback ev) - (fd-entry-fd fd-entry) - event-type - (if errorp :error nil)) - (when-let (timer (fd-handler-timer ev)) - (reschedule-timer-relative-to-now timer now)) - (fd-handler-one-shot-p ev))) + (when ev + (funcall (fd-handler-callback ev) + (fd-entry-fd fd-entry) + event-type + (if errorp :error nil)) + (when-let (timer (fd-handler-timer ev)) + (reschedule-timer-relative-to-now timer now)) + (fd-handler-one-shot-p ev))))
(defun dispatch-fd-timeouts (events) (dolist (ev events)
Hello,
After a talk with Stelian about the previous version of this patch, I see now my initial solution was incorrect. Here is a corrected version of it.
The purpose of this patch is to fix %remove-handlers and %dispatch-event so they don't try to invoke or otherwise misuse a NIL callback handler on a ready socket.
Thank you.
-pete
diff --git a/src/multiplex/event-loop.lisp b/src/multiplex/event-loop.lisp index 35879fd..a0b6ab1 100644 --- a/src/multiplex/event-loop.lisp +++ b/src/multiplex/event-loop.lisp @@ -313,7 +313,7 @@ within the extent of BODY. Closes VAR." (when (and eventsp one-shot) (setf exit-p t))))))
(defun %remove-handlers (event-base event-list) - (loop :for ev :in event-list + (loop :for ev :in (remove-if #'null event-list) :for fd := (fd-handler-fd ev) :for fd-entry := (fd-entry-of event-base fd) :do (%remove-io-handler event-base fd fd-entry ev))) @@ -352,13 +352,14 @@ within the extent of BODY. Closes VAR."
(defun %dispatch-event (fd-entry event-type errorp now) (let ((ev (fd-entry-handler fd-entry event-type))) - (funcall (fd-handler-callback ev) - (fd-entry-fd fd-entry) - event-type - (if errorp :error nil)) - (when-let (timer (fd-handler-timer ev)) - (reschedule-timer-relative-to-now timer now)) - (fd-handler-one-shot-p ev))) + (when ev + (funcall (fd-handler-callback ev) + (fd-entry-fd fd-entry) + event-type + (if errorp :error nil)) + (when-let (timer (fd-handler-timer ev)) + (reschedule-timer-relative-to-now timer now)) + (fd-handler-one-shot-p ev))))
(defun dispatch-fd-timeouts (events) (dolist (ev events)
On Tue, 2010-03-02 at 21:18 -0600, Peter Keller wrote:
Hello,
After a talk with Stelian about the previous version of this patch, I see now my initial solution was incorrect. Here is a corrected version of it.
The purpose of this patch is to fix %remove-handlers and %dispatch-event so they don't try to invoke or otherwise misuse a NIL callback handler on a ready socket.
Thanks, I applied your patch with a small modification.
On Sun, Mar 07, 2010 at 12:13:46AM +0100, Stelian Ionescu wrote:
On Tue, 2010-03-02 at 21:18 -0600, Peter Keller wrote:
The purpose of this patch is to fix %remove-handlers and %dispatch-event so they don't try to invoke or otherwise misuse a NIL callback handler on a ready socket.
Thanks, I applied your patch with a small modification.
Ah, I see. That modification makes perfect sense.
Thank you!
-pete