Don't call put-message without unwinding the stack

When handling exceptions, as this is error prone.
This commit is contained in:
Christopher Baines 2025-04-01 17:46:39 +03:00
parent e1858dfff5
commit 8c0f04be4f

View file

@ -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))