From: Carlos Amedee Date: Fri, 9 May 2025 21:44:35 +0000 (-0400) Subject: internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer X-Git-Tag: go1.25rc1~282 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c44c4de51b68a88e2b8e4a0ae102f941155522d0;p=gostls13.git internal/poll: use runtime.AddCleanup instead of runtime.SetFinalizer Replace the use of SetFinalizer with AddCleanup. For #70907 Change-Id: I0cb2c2985eb9285e5f92be9dbcb9d77acc0f59c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/671441 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go index 193a56215c..4409d2f336 100644 --- a/src/internal/poll/splice_linux.go +++ b/src/internal/poll/splice_linux.go @@ -9,7 +9,6 @@ import ( "runtime" "sync" "syscall" - "unsafe" ) const ( @@ -179,10 +178,7 @@ type splicePipeFields struct { type splicePipe struct { splicePipeFields - - // We want to use a finalizer, so ensure that the size is - // large enough to not use the tiny allocator. - _ [24 - unsafe.Sizeof(splicePipeFields{})%24]byte + cleanup runtime.Cleanup } // splicePipePool caches pipes to avoid high-frequency construction and destruction of pipe buffers. @@ -197,7 +193,10 @@ func newPoolPipe() any { if p == nil { return nil } - runtime.SetFinalizer(p, destroyPipe) + + p.cleanup = runtime.AddCleanup(p, func(spf splicePipeFields) { + destroyPipe(&splicePipe{splicePipeFields: spf}) + }, p.splicePipeFields) return p } @@ -214,7 +213,7 @@ func putPipe(p *splicePipe) { // If there is still data left in the pipe, // then close and discard it instead of putting it back into the pool. if p.data != 0 { - runtime.SetFinalizer(p, nil) + p.cleanup.Stop() destroyPipe(p) return }