From 3bfe99d3d855a03a806dc66c8c215ba69d2dd67b Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 18 Feb 2026 20:00:32 +0900 Subject: [PATCH] internal/lockedfile: keep objects alive while stopping cleanups Fixes https://go.dev/issues/74780. Signed-off-by: Ophestra --- internal/lockedfile/internal/filelock/filelock.go | 8 -------- internal/lockedfile/lockedfile.go | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/lockedfile/internal/filelock/filelock.go b/internal/lockedfile/internal/filelock/filelock.go index d373318..f0452f0 100644 --- a/internal/lockedfile/internal/filelock/filelock.go +++ b/internal/lockedfile/internal/filelock/filelock.go @@ -8,7 +8,6 @@ package filelock import ( - "errors" "io/fs" ) @@ -74,10 +73,3 @@ func (lt lockType) String() string { return "Unlock" } } - -// IsNotSupported returns a boolean indicating whether the error is known to -// report that a function is not supported (possibly for a specific input). -// It is satisfied by errors.ErrUnsupported as well as some syscall errors. -func IsNotSupported(err error) bool { - return errors.Is(err, errors.ErrUnsupported) -} diff --git a/internal/lockedfile/lockedfile.go b/internal/lockedfile/lockedfile.go index 8bd2ffb..f48124f 100644 --- a/internal/lockedfile/lockedfile.go +++ b/internal/lockedfile/lockedfile.go @@ -94,6 +94,11 @@ func (f *File) Close() error { err := closeFile(f.osFile.File) f.cleanup.Stop() + // f may be dead at the moment after we access f.cleanup, + // so the cleanup can fire before Stop completes. Keep f + // alive while we call Stop. See the documentation for + // runtime.Cleanup.Stop. + runtime.KeepAlive(f) return err }