aboutsummaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-12-03 16:59:46 +0900
committerOphestra <cat@gensokyo.uk>2026-12-03 16:59:46 +0900
commitb0110977521410749ae02fb8cbec9220be7e7894 (patch)
tree3681591bafcfd1b01fe4289a58e1f40b5a17a183 /pkg
parent6256fe132b98c4a8db06636e8b00f55dd459bf4b (diff)
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 <cat@gensokyo.uk>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/pkg.go39
1 files changed, 31 insertions, 8 deletions
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()))