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

runtime: add debug mode for finalizers and cleanups #72949

Open
mknyszek opened this issue Mar 19, 2025 · 1 comment
Open

runtime: add debug mode for finalizers and cleanups #72949

mknyszek opened this issue Mar 19, 2025 · 1 comment
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
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