From 96b65f16fb2a6f5d568d7709a86e2307ef70fe0f Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 4 Oct 2020 10:18:53 +0100 Subject: [PATCH] Avoid fiber deadlocks Channels don't represent some channel on which messages travel, at least not a very long one because it can't accommodate any messages. They simply represent a direct exchange of the message between a sender and receiver. Because of this, put-message blocks the fiber, and if all the threads on the other end are waiting for replies to be received, then you have a deadlock. To avoid this situation, spawn new fibers to send the messages. I think this works at least, although I'm unsure how sensible it is. --- guix-data-service/utils.scm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/guix-data-service/utils.scm b/guix-data-service/utils.scm index 855c819..c50cb64 100644 --- a/guix-data-service/utils.scm +++ b/guix-data-service/utils.scm @@ -99,7 +99,9 @@ (define (defer-to-thread-pool-channel thunk) (make-thread-pool-channel!) (let ((reply (make-channel))) - (put-message %thread-pool-channel (cons reply thunk)) + (spawn-fiber + (lambda () + (put-message %thread-pool-channel (cons reply thunk)))) reply)) (define (fetch-result-of-defered-thunk reply-channel)