diff --git a/pkgs/racket-pkgs/racket-test/tests/racket/sandbox.rktl b/pkgs/racket-pkgs/racket-test/tests/racket/sandbox.rktl index 261bb8f4f8..24a9192817 100644 --- a/pkgs/racket-pkgs/racket-test/tests/racket/sandbox.rktl +++ b/pkgs/racket-pkgs/racket-test/tests/racket/sandbox.rktl @@ -666,6 +666,26 @@ r1) (test #t equal? r1 r2)) +;; ---------------------------------------- +;; Check that sandbox is not flushed if +;; its custodian has been shut down: + +(let () + (define p (make-plumber)) + + (define e0 + (parameterize ([current-plumber p]) + (call-with-trusted-sandbox-configuration + (lambda () + (make-evaluator 'racket/base))))) + + (e0 '(require racket/sandbox)) + (e0 '(make-evaluator 'racket/base)) + + (kill-evaluator e0) + ;; e's plumber should not be flushed: + (plumber-flush-all p)) + ;; ---------------------------------------- ;; Backup test for one in "thread.rktl", since this sandbox test diff --git a/pkgs/sandbox-lib/racket/sandbox.rkt b/pkgs/sandbox-lib/racket/sandbox.rkt index b157bfceaf..bc56ffea2a 100644 --- a/pkgs/sandbox-lib/racket/sandbox.rkt +++ b/pkgs/sandbox-lib/racket/sandbox.rkt @@ -1032,7 +1032,12 @@ (let ([p (make-plumber)]) (define fh (plumber-add-flush! (current-plumber) (lambda (fh) - (unless terminated? + (unless (or terminated? + ;; The evaluator thread may have terminated + ;; asynchronously, such as through an enclosing + ;; custodian's shutdown + (and user-thread + (thread-dead? user-thread))) (call-in-sandbox-context evaluator (lambda ()