We should add a sentence to the finalizer and cleanup documentation that makes it abundantly clear a finalizer/cleanup can hold up other ones. We should also list this as one of the complications of using them in https://go.dev/doc/gc-guide.

Comment From: gabyhelp

Related Issues

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

Comment From: camdenmcgath

@mknyszek are you working on this? I'd love to contribute some documentation if it's still needed.

Comment From: mknyszek

@camdenmcgath Please go ahead! Sorry for the delay, I was unavailable until today.

Comment From: gopherbot

Change https://go.dev/cl/671437 mentions this issue: runtime: report finalizer and cleanup queue length with checkfinalizer>0

Comment From: mknyszek

Hm, reading the cleanup documentation again, I do think it is pretty clear:

// If a cleanup function must run for a long time, it should create a new goroutine
// to avoid blocking the execution of other cleanups.

Same for finalizers:

// A single goroutine runs all finalizers for a program, sequentially.
// If a finalizer must run for a long time, it should do so by starting a new goroutine.

I think maybe we just need to make this clear in the GC guide, then.