Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register-finalizer-and-custodian-shutdown does not run finalizer in Racket CS #3352

Closed
samdphillips opened this issue Aug 14, 2020 · 1 comment
Labels
bug Something isn't working correctly racket-cs Specific to Racket-on-Chez

Comments

@samdphillips
Copy link
Contributor

What version of Racket are you using?

7.8 [cs]

What program did you run?

#lang racket/base

;; finalized-simple.rkt

(require ffi/unsafe/custodian)

;; hijack name for logging
(define (log-info x)
  (log-message (current-logger) 'info 'finalize x))

(define (finalize x)
  (log-info "finalizing"))

(define the-box
  (let ([v "a value"])
    (register-finalizer-and-custodian-shutdown v finalize #:at-exit? #t)
    (log-info "created")
    (box v)))

(module* A #f
  (set-box! the-box #f)
  (collect-garbage 'major)
  (collect-garbage 'major)
  (collect-garbage 'major)
  (log-info "exiting"))

(module* B #f
  (log-info "exiting"))

What should have happened?

Running either submodule should run the finalize procedure. This works in 7.8[bc] but not 7.8[cs].

Racket 7.8[cs]

$ PLTSTDERR="info@finalize" racket -e '(require (submod "finalized-simple.rkt" A))'
finalize: created
finalize: exiting
$ PLTSTDERR="info@finalize" racket -e '(require (submod "finalized-simple.rkt" B))'
finalize: created
finalize: exiting

Racket 7.8[bc] - works

$ PLTSTDERR="info@finalize" racket -e '(require (submod "finalized-simple.rkt" A))'
finalize: created
finalize: exiting
finalize: finalizing
$ PLTSTDERR="info@finalize" racket -e '(require (submod "finalized-simple.rkt" B))'
finalize: created
finalize: exiting
finalize: finalizing

Please include any other relevant details

Linux 5.4.0-42-generic x86_64
Ubuntu 20.04.1 LTS

Racket 7.8[cs] installed from Racket Linux Installer

mflatt added a commit that referenced this issue Aug 15, 2020
@mflatt mflatt closed this as completed in 91abd02 Aug 15, 2020
@mflatt mflatt reopened this Aug 16, 2020
@mflatt
Copy link
Member

mflatt commented Aug 16, 2020

The repair wasn't right: bf06162.

@mflatt mflatt closed this as completed in 4a4e12b Aug 16, 2020
@jackfirth jackfirth added bug Something isn't working correctly racket-cs Specific to Racket-on-Chez labels Aug 16, 2020
maueroats pushed a commit to maueroats/racket that referenced this issue Jun 17, 2021
maueroats pushed a commit to maueroats/racket that referenced this issue Jun 17, 2021
Change the regular weak reference in a custodian, which allows
`will-executor`-based finalization, to a "late" weakk reference, which
allows both `will-executor` and `register-finalizer` finalization.

Closes racket#3352
maueroats pushed a commit to maueroats/racket that referenced this issue Jun 17, 2021
Refine the approach in 91abd02 so that it's only used when needed
to work for the combination of custodian management and unsafe
finalization.

Also, improve the documentation to clarify the constraints on
`register-finalize` due to its implementation in CS by ordered
finalization. This constraint is also reflected in a new `#:ordered?`
argument to `register-custodian-shutdown`. Any existing code that uses
`register-custodian-shutdown` plus `register-finalizer` directly
instead of `register-finalizer-and-custodian-shutdown` would need to
be updated for Racket CS, but code like that should be rare to
nonexistent.

Closes racket#3352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly racket-cs Specific to Racket-on-Chez
Projects
None yet
Development

No branches or pull requests

3 participants