Address issue with failures when creating resource pool resources
All checks were successful
/ test (push) Successful in 5s

Previously failures could lead to no resources in the pool, and
waiters which will never get a resource. Retrying here fixes that
issue, although maybe another approach is needed that keeps track of
new resources being created, as that'll allow keeping track of this
when destroying resource pools.
This commit is contained in:
Christopher Baines 2026-01-12 10:50:11 +00:00
parent 094259b049
commit 5260c38b5e

View file

@ -562,13 +562,15 @@
#f #f
(raise-exception exn))) (raise-exception exn)))
(lambda () (lambda ()
(let loop ()
(let ((success?
(with-parallelism-limiter (with-parallelism-limiter
return-new-resource/parallelism-limiter return-new-resource/parallelism-limiter
(let ((max-size (let ((max-size
(assq-ref (resource-pool-configuration pool) (assq-ref (resource-pool-configuration pool)
'max-size)) 'max-size))
(size (count-resources resources))) (size (count-resources resources)))
(unless (>= size max-size) (or (>= size max-size)
(with-exception-handler (with-exception-handler
(lambda _ #f) (lambda _ #f)
(lambda () (lambda ()
@ -585,8 +587,18 @@
(let ((new-resource (let ((new-resource
(start-stack #t (return-new-resource)))) (start-stack #t (return-new-resource))))
(put-message channel (put-message channel
(list 'add-resource new-resource)))))) (list 'add-resource new-resource)))
#:unwind? #t))))) #t)))
#:unwind? #t))))))
(unless success?
;; TODO Maybe this should be configurable?
(sleep 1)
;; Important to retry here and eventually create
;; a new resource, as there might be waiters
;; stuck waiting for a resource, especially if
;; the pool is empty.
(loop)))))
#:unwind? #t)))) #:unwind? #t))))
(define (spawn-fiber-to-destroy-resource resource-id resource-value) (define (spawn-fiber-to-destroy-resource resource-id resource-value)