From 11789ff8b0e1edaaeaa0cb387a674d32c1ba4b87 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 30 Apr 2019 13:59:32 -0600 Subject: [PATCH] io: fix socket/fd port custodian registration Register the port, not the file descriptor, especially since a TCP connection can have ports that share a file descriptor. Also, I think a weak reference in the custodian doesn't work as intended (visible through finalization) if the file descriptor is referenced with a callback that closes over the port. --- racket/src/io/network/tcp-listen.rkt | 1 + racket/src/io/port/fd-port.rkt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/racket/src/io/network/tcp-listen.rkt b/racket/src/io/network/tcp-listen.rkt index bb2c611c88..bc9b4807e8 100644 --- a/racket/src/io/network/tcp-listen.rkt +++ b/racket/src/io/network/tcp-listen.rkt @@ -4,6 +4,7 @@ "../host/rktio.rkt" "../security/main.rkt" "../sandman/main.rkt" + "../format/main.rkt" "port-number.rkt" "address.rkt" "error.rkt") diff --git a/racket/src/io/port/fd-port.rkt b/racket/src/io/port/fd-port.rkt index 6be1f68845..e2f2d4fac8 100644 --- a/racket/src/io/port/fd-port.rkt +++ b/racket/src/io/port/fd-port.rkt @@ -432,9 +432,9 @@ (define (register-fd-close custodian fd fd-refcount flush-handle port) (unsafe-custodian-register custodian - fd + port ;; in atomic mode - (lambda (fd) + (lambda (port) (when flush-handle (plumber-flush-handle-remove! flush-handle)) (if (input-port? port)