From 078ed985c17714db5bf9e985728289ba40d313d5 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 12 Dec 2016 12:44:53 -0600 Subject: [PATCH] actors: Fix "unrewindable continuation" issue with error handling code. * 8sync/systems/actors.scm (hive-reply-with-error, hive-process-message): Move responding with error to outside of the catch statement. This was resulting in unrewindable continuation issues. --- 8sync/systems/actors.scm | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/8sync/systems/actors.scm b/8sync/systems/actors.scm index ce46f63..caee695 100644 --- a/8sync/systems/actors.scm +++ b/8sync/systems/actors.scm @@ -437,7 +437,10 @@ more compact following syntax: (actor-id hive) '*error* new-message-body #:in-reply-to (message-id original-message)))) - (8sync (hive-process-message hive new-message)))) + ;; We only return a thunk, rather than run 8sync here, because if + ;; we ran 8sync in the middle of a catch we'd end up with an + ;; unresumable continuation. + (lambda () (hive-process-message hive new-message)))) (define-method (hive-process-message (hive ) message) "Handle one message, or forward it via an ambassador" @@ -459,6 +462,7 @@ more compact following syntax: actor)) (define (call-catching-coroutine thunk) + (define queued-error-handling-thunk #f) (define (call-catching-errors) ;; TODO: maybe parameterize (or attach to hive) and use ;; maybe-catch-all from agenda.scm @@ -475,9 +479,16 @@ more compact following syntax: (if (message-needs-reply? message) ;; If the message is waiting on a reply, let them know ;; something went wrong. - (hive-reply-with-error hive message key args)) + ;; However, we have to do it outside of this catch + ;; routine, or we'll end up in an unrewindable continuation + ;; situation. + (set! queued-error-handling-thunk + (hive-reply-with-error hive message key args))) ;; print error message - (apply print-error-and-continue key args)))) + (apply print-error-and-continue key args))) + ;; @@: This is a kludge. See above for why. + (if queued-error-handling-thunk + (8sync (queued-error-handling-thunk)))) (call-with-prompt (hive-prompt hive) call-catching-errors (lambda (kont actor message) -- 2.31.1