Skip to content

runtime: add debug mode for finalizers and cleanups #72949

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

Open
mknyszek opened this issue Mar 19, 2025 · 6 comments
Open

runtime: add debug mode for finalizers and cleanups #72949

mknyszek opened this issue Mar 19, 2025 · 6 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Implementation Issues describing a semantics-preserving change to the Go implementation.
Milestone

Comments

@mknyszek
Copy link
Contributor

Finalizers are notoriously difficult to work with due to all the subtleties you need to be aware of. Cleanups have resolved several finalizer issues, but still carry some of the same issues.

To help detect misuse, I'd like to propose a new debug mode (GODEBUG) that runs a partial GC cycle during mark termination to detect reference cycles for finalizers and references from cleanup roots to the objects they're attached to. This debug mode can also include three additional checkers:

  • Detect when a finalizer or cleanup function fully blocks the goroutine it's on and report it as a potential issue.
  • Detect when a finalizer or cleanup is attached to a tiny alloc block. This will require additional state tracking.

I'll also note that execution traces would be a great place to analyze inefficiencies due to finalizers and/or cleanups.

https://go.dev/cl/634599 is a start.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Mar 19, 2025
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the Implementation Issues describing a semantics-preserving change to the Go implementation. label Mar 19, 2025
@mknyszek mknyszek self-assigned this Mar 19, 2025
@mknyszek mknyszek added this to the Go1.25 milestone Mar 19, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/634599 mentions this issue: runtime: add new GODEBUG checkfinalizer

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/662135 mentions this issue: runtime: annotate checkfinalizers reports with source and type info

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/662038 mentions this issue: runtime: add scan trace for checkfinalizers>1

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/662039 mentions this issue: runtime: add package doc for checkfinalizer mode

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/662037 mentions this issue: runtime: mark and identify tiny blocks in checkfinalizers mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Implementation Issues describing a semantics-preserving change to the Go implementation.
Projects
Development

No branches or pull requests

3 participants