diff --git a/knots/resource-pool.scm b/knots/resource-pool.scm index f00e05b..73f7083 100644 --- a/knots/resource-pool.scm +++ b/knots/resource-pool.scm @@ -558,9 +558,8 @@ (lambda (exn) ;; This can happen if the resource pool is destroyed very ;; quickly - (if (resource-pool-destroyed-error? exn) - #f - (raise-exception exn))) + (unless (resource-pool-destroyed-error? exn) + (raise-exception exn))) (lambda () (with-parallelism-limiter return-new-resource/parallelism-limiter @@ -589,11 +588,13 @@ #:unwind? #t))))) #:unwind? #t)))) - (define (spawn-fiber-to-destroy-resource resource-id resource-value) + (define (spawn-fiber-to-destroy-resource resource-id resource-details) (spawn-fiber (lambda () (let loop () - (let* ((success? + (let* ((resource + (resource-details-value resource-details)) + (success? (with-exception-handler (lambda _ #f) (lambda () @@ -607,7 +608,7 @@ (print-backtrace-and-exception/knots exn) (raise-exception exn)) (lambda () - (start-stack #t (destructor resource-value)) + (start-stack #t (destructor resource)) #t))) #:unwind? #t))) @@ -661,8 +662,7 @@ destructor) (spawn-fiber-to-destroy-resource resource-id - (resource-details-value - (hash-ref resources resource-id)))) + (hash-ref resources resource-id))) (hash-remove! resources resource-id) @@ -886,8 +886,7 @@ lifetime)) (begin (spawn-fiber-to-destroy-resource resource-id - (resource-details-value - resource-details)) + resource-details) (loop next-resource-id available waiters)) @@ -957,8 +956,7 @@ (hash-ref resources resource-id))) (spawn-fiber-to-destroy-resource resource-id - (resource-details-value - resource-details)) + resource-details) (loop next-resource-id available @@ -1035,8 +1033,7 @@ (lambda (resource-id) (spawn-fiber-to-destroy-resource resource-id - (resource-details-value - (hash-ref resources resource-id)))) + (hash-ref resources resource-id))) resources-to-destroy)) (loop next-resource-id @@ -1075,9 +1072,8 @@ (lambda (resource-id) (spawn-fiber-to-destroy-resource resource-id - (resource-details-value - (hash-ref resources - resource-id)))) + (hash-ref resources + resource-id))) available)) ;; Do this in parallel to avoid deadlocks between the