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: finalizers/cleanups can exit the finalizer goroutine #71824

Open
prattmic opened this issue Feb 18, 2025 · 3 comments
Open

runtime: finalizers/cleanups can exit the finalizer goroutine #71824

prattmic opened this issue Feb 18, 2025 · 3 comments
Assignees
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@prattmic
Copy link
Member

All finalizers and cleanups run on a single goroutine started internally in the runtime. If a finalizer/cleanup calls Goexit, it will do what it says on the tin and exit the finalizer goroutine. No more finalizers/cleanups will run after that point.

At minimum, Goexit should probably detect this case and throw.

@ianlancetaylor put together https://go.dev/play/p/7jRsXx0W2OZ, which shows that the finalizers never run, but otherwise no error is reported.

cc @golang/runtime

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 18, 2025
@prattmic prattmic added this to the Go1.25 milestone Feb 18, 2025
@gabyhelp
Copy link

Related Issues

Related Documentation

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

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Feb 18, 2025
@mknyszek
Copy link
Contributor

Can we change this behavior to crashing at this point? It's almost certainly a bug, but crashing the program might cause programs that run OK to experience issues. Maybe it would be better to just start another finalizer goroutine when that one exits? There would have to be some state reconstruction by the new goroutine which might get complicated.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 19, 2025
@ianlancetaylor
Copy link
Member

I think it's OK to crash the program if a finalizer/cleanup exits the goroutine. It's clearly a programming error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

5 participants