From b0110977521410749ae02fb8cbec9220be7e7894 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 3 Dec 2026 16:59:46 +0900 Subject: pkg: exempt SIGKILL termination from recording These generally only happen on termination via cancellation, in which case the status file is not worth preserving. Signed-off-by: Ophestra --- pkg/pkg.go | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'pkg') diff --git a/pkg/pkg.go b/pkg/pkg.go index 2d102666..49f6f5a1 100644 --- a/pkg/pkg.go +++ b/pkg/pkg.go @@ -24,6 +24,7 @@ import ( "maps" "math" "os" + "os/exec" "path/filepath" "runtime" "slices" @@ -224,6 +225,24 @@ func (t *TContext) GetStatusWriter() (io.Writer, error) { return t.status, err } +// isReportable returns whether an error should be recorded. A typical example +// of a non-reportable error is [Collected]. +func isReportable(err error) bool { + if IsCollected(err) { + return false + } + + var wstatus syscall.WaitStatus + if e, ok := errors.AsType[*exec.ExitError](err); ok { + if wstatus, ok = e.Sys().(syscall.WaitStatus); ok && + wstatus.Signaled() && wstatus.Signal() == syscall.SIGKILL { + return false + } + } + + return true +} + // destroy destroys the temporary directory and joins its errors with the error // referred to by errP. If the error referred to by errP is non-nil, the work // directory is removed similarly. [Cache] is responsible for making sure work @@ -259,14 +278,18 @@ func (t *TContext) destroy(errP *error) { *errP = errors.Join(*errP, err) } if *errP != nil { - *errP = errors.Join(*errP, os.Rename( - t.statusPath.String(), t.cache.base.Append( - dirFault, - t.ids+"."+strconv.FormatUint(uint64( - time.Now().UnixNano(), - ), 10), - ).String(), - )) + if isReportable(*errP) { + *errP = errors.Join(*errP, os.Rename( + t.statusPath.String(), t.cache.base.Append( + dirFault, + t.ids+"."+strconv.FormatUint(uint64( + time.Now().UnixNano(), + ), 10), + ).String(), + )) + } else { + *errP = errors.Join(*errP, os.Remove(t.statusPath.String())) + } if t.statusSPath != nil { t.cache.checksumMu.Lock() *errP = errors.Join(*errP, os.Remove(t.statusSPath.String())) -- cgit v1.3.1