From 9cce89fc0122126b1ccd180d637f83a3d1f00cd7 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 25 Nov 2025 09:58:45 +0000 Subject: [PATCH 1/2] Change how spawn-fiber-to-destroy-resource is used And fix a couple of incorrect uses. --- knots/resource-pool.scm | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/knots/resource-pool.scm b/knots/resource-pool.scm index 73f7083..739ec4f 100644 --- a/knots/resource-pool.scm +++ b/knots/resource-pool.scm @@ -588,13 +588,11 @@ #:unwind? #t))))) #:unwind? #t)))) - (define (spawn-fiber-to-destroy-resource resource-id resource-details) + (define (spawn-fiber-to-destroy-resource resource-id resource-value) (spawn-fiber (lambda () (let loop () - (let* ((resource - (resource-details-value resource-details)) - (success? + (let* ((success? (with-exception-handler (lambda _ #f) (lambda () @@ -608,7 +606,7 @@ (print-backtrace-and-exception/knots exn) (raise-exception exn)) (lambda () - (start-stack #t (destructor resource)) + (start-stack #t (destructor resource-value)) #t))) #:unwind? #t))) @@ -662,7 +660,8 @@ destructor) (spawn-fiber-to-destroy-resource resource-id - (hash-ref resources resource-id))) + (resource-details-value + (hash-ref resources resource-id)))) (hash-remove! resources resource-id) @@ -886,7 +885,8 @@ lifetime)) (begin (spawn-fiber-to-destroy-resource resource-id - resource-details) + (resource-details-value + resource-details)) (loop next-resource-id available waiters)) @@ -956,7 +956,8 @@ (hash-ref resources resource-id))) (spawn-fiber-to-destroy-resource resource-id - resource-details) + (resource-details-value + resource-details)) (loop next-resource-id available @@ -1033,7 +1034,8 @@ (lambda (resource-id) (spawn-fiber-to-destroy-resource resource-id - (hash-ref resources resource-id))) + (resource-details-value + (hash-ref resources resource-id)))) resources-to-destroy)) (loop next-resource-id @@ -1072,8 +1074,9 @@ (lambda (resource-id) (spawn-fiber-to-destroy-resource resource-id - (hash-ref resources - resource-id))) + (resource-details-value + (hash-ref resources + resource-id)))) available)) ;; Do this in parallel to avoid deadlocks between the From 8100d36aa5bebb6c6fab114ae5595ace2be43b2e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 25 Nov 2025 09:58:58 +0000 Subject: [PATCH 2/2] Avoid errors about returning no values from a exception handler --- knots/resource-pool.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/knots/resource-pool.scm b/knots/resource-pool.scm index 739ec4f..f00e05b 100644 --- a/knots/resource-pool.scm +++ b/knots/resource-pool.scm @@ -558,8 +558,9 @@ (lambda (exn) ;; This can happen if the resource pool is destroyed very ;; quickly - (unless (resource-pool-destroyed-error? exn) - (raise-exception exn))) + (if (resource-pool-destroyed-error? exn) + #f + (raise-exception exn))) (lambda () (with-parallelism-limiter return-new-resource/parallelism-limiter