[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: utils: Handle errors in worker threads.

From: Christopher Baines
Subject: branch master updated: utils: Handle errors in worker threads.
Date: Wed, 05 Feb 2020 13:13:07 -0500

This is an automated email from the git hooks/post-receive script.

cbaines pushed a commit to branch master
in repository guix-cuirass.

The following commit(s) were added to refs/heads/master by this push:
     new bb22518  utils: Handle errors in worker threads.
bb22518 is described below

commit bb225189fd56d89ec8be926dda269295ccbfe918
Author: Christopher Baines <address@hidden>
AuthorDate: Mon Feb 3 12:58:22 2020 +0100

    utils: Handle errors in worker threads.
    Previously, if an error occurred, the worker fiber simply never sends a
    reply. In the case of HTTP requests to Cuirass, where an exception occurs 
    performing a database query, the fiber handling the request blocks as it 
    gets a response. I think that this has the potential to cause the process to
    hit file descriptor limits, as the connections are never responded to.
    This is fixed by responding with the details of the exception, and then
    throwing it within the fiber that made the call.
    * src/cuirass/utils.scm (make-worker-thread-channel): Catch exceptions when
    calling proc.
    (call-with-worker-thread): Handle receiving exceptions from the worker 
 src/cuirass/utils.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm
index f3ba18d..0bcbb35 100644
--- a/src/cuirass/utils.scm
+++ b/src/cuirass/utils.scm
@@ -114,7 +114,12 @@ arguments of the worker thread procedure."
                 (let loop ()
                   (match (get-message channel)
                     (((? channel? reply) . (? procedure? proc))
-                     (put-message reply (apply proc args))))
+                     (put-message reply
+                                  (catch #t
+                                    (lambda ()
+                                      (apply proc args))
+                                    (lambda (key . args)
+                                      (cons* 'worker-thread-error key 
        (iota parallelism))
@@ -127,7 +132,10 @@ If already in the worker thread, call PROC immediately."
         (apply proc args)
         (let ((reply (make-channel)))
           (put-message channel (cons reply proc))
-          (get-message reply)))))
+          (match (get-message reply)
+            (('worker-thread-error key args ...)
+             (apply throw key args))
+            (result result))))))
 (define-syntax-rule (with-worker-thread channel (vars ...) exp ...)
   "Evaluate EXP... in the worker thread corresponding to CHANNEL.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]