From e8832fbcc743c09e7803eac529d39d92bbe7103a Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Tue, 23 Oct 2018 18:15:58 +0200 Subject: [PATCH] cs: remove plumber flush callback when custodian closes fd output port Previously, the following program would print "error writing to stream port" on program exit. (define cust (make-custodian)) (define out (parameterize ((current-custodian cust)) (open-output-file "test.data" #:exists 'truncate))) (write-string "This needs flushing...\n" out) (custodian-shutdown-all cust) (exit 0) --- racket/src/io/port/fd-port.rkt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/racket/src/io/port/fd-port.rkt b/racket/src/io/port/fd-port.rkt index be41937975..4d97f1403a 100644 --- a/racket/src/io/port/fd-port.rkt +++ b/racket/src/io/port/fd-port.rkt @@ -87,7 +87,7 @@ [() (buffer-control)] [(pos) (buffer-control pos)])))) (define custodian-reference - (register-fd-close cust fd fd-refcount port)) + (register-fd-close cust fd fd-refcount #f port)) port) ;; ---------------------------------------- @@ -230,7 +230,7 @@ [(mode) (set! buffer-mode mode)]))) (define custodian-reference - (register-fd-close cust fd fd-refcount port)) + (register-fd-close cust fd fd-refcount flush-handle port)) (set-fd-evt-closed! evt (core-port-closed port)) @@ -331,12 +331,14 @@ ;; ---------------------------------------- -(define (register-fd-close custodian fd fd-refcount port) +(define (register-fd-close custodian fd fd-refcount flush-handle port) (define closed (core-port-closed port)) (unsafe-custodian-register custodian fd ;; in atomic mode (lambda (fd) + (when flush-handle + (plumber-flush-handle-remove! flush-handle)) (fd-close fd fd-refcount) (set-closed-state! closed)) #f