diff --git a/knots/resource-pool.scm b/knots/resource-pool.scm index f4522be..1b50482 100644 --- a/knots/resource-pool.scm +++ b/knots/resource-pool.scm @@ -650,12 +650,27 @@ available. Return the resource once PROC has returned." (lambda () (with-exception-handler (lambda (exn) - (print-backtrace-and-exception/knots exn) + ;; Unwind the stack before calling put-message, as + ;; this avoids inconsistent behaviour with + ;; continuation barriers (put-message (resource-pool-channel pool) `(return ,resource)) (raise-exception exn)) (lambda () - (proc resource)))) + (with-exception-handler + (lambda (exn) + (match (fluid-ref %stacks) + ((stack-tag . prompt-tag) + (let ((stack (make-stack #t + 0 prompt-tag + 0 (and prompt-tag 1)))) + (raise-exception + (make-exception + exn + (make-knots-exception stack))))))) + (lambda () + (proc resource)))) + #:unwind? #t)) (lambda vals (put-message (resource-pool-channel pool) `(return ,resource))