From 5c521961b577582e32faa22cf9fc2260d353ce07 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 9 May 2014 16:27:04 -0600 Subject: [PATCH] racket/sandbox: fix guard on attempt to flush sandbox plumber --- .../racket-test/tests/racket/sandbox.rktl | 20 +++++++++++++++++++ pkgs/sandbox-lib/racket/sandbox.rkt | 7 ++++++- 2 files changed, 26 insertions(+), 1 deletion(-) 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 ()