From 2c699b979476366a95f98d0e852218e69591351e Mon Sep 17 00:00:00 2001 From: Daniel Bennett Date: Mon, 18 Aug 2025 10:19:14 -0400 Subject: [PATCH] sysbatch: fix panic from reschedule block (#26534) * fix panic from nil ReschedulePolicy commit 279775082c3aa43828faa7e0d22b15561d36ce68 (pr #26279) intended to return an error for sysbatch jobs with a reschedule block, but in bypassing populating the `ReschedulePolicy`'s pointer fields, a nil pointer panic occurred before the job could get rejected with the intended error. in particular, in `command/agent/job_endpoint.go`, `func ApiTgToStructsTG`, ``` if taskGroup.ReschedulePolicy != nil { tg.ReschedulePolicy = &structs.ReschedulePolicy{ Attempts: *taskGroup.ReschedulePolicy.Attempts, Interval: *taskGroup.ReschedulePolicy.Interval, ``` `*taskGroup.ReschedulePolicy.Interval` was a nil pointer. * fix e2e test jobs --- api/tasks.go | 4 +++- e2e/docker_registry/registry-auths.hcl | 4 ---- e2e/docker_registry/registry.hcl | 5 ----- e2e/metrics/input/setup.hcl | 4 ---- e2e/v3/jobs3/jobs3.go | 1 + 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/api/tasks.go b/api/tasks.go index 57d868c87..db00931d3 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -202,7 +202,7 @@ func (r *ReschedulePolicy) Merge(rp *ReschedulePolicy) { } func (r *ReschedulePolicy) Canonicalize(jobType string) { - if r == nil || jobType == JobTypeSystem || jobType == JobTypeSysbatch { + if r == nil { return } dp := NewDefaultReschedulePolicy(jobType) @@ -289,6 +289,8 @@ func NewDefaultReschedulePolicy(jobType string) *ReschedulePolicy { // GH-7203: it is possible an unknown job type is passed to this // function and we need to ensure a non-nil object is returned so that // the canonicalization runs without panicking. + // This also applies to batch/sysbatch jobs, which do not reschedule; + // we still want to return a safe object. dp = &ReschedulePolicy{ Attempts: pointerOf(0), Interval: pointerOf(time.Duration(0)), diff --git a/e2e/docker_registry/registry-auths.hcl b/e2e/docker_registry/registry-auths.hcl index c48f63fdb..e8b85e7cb 100644 --- a/e2e/docker_registry/registry-auths.hcl +++ b/e2e/docker_registry/registry-auths.hcl @@ -46,10 +46,6 @@ job "registry-auths" { } group "create-files" { - reschedule { - attempts = 0 - unlimited = false - } # write out the test.sh file into var.helper_dir task "create-helper-file" { diff --git a/e2e/docker_registry/registry.hcl b/e2e/docker_registry/registry.hcl index 2f52b5cad..c23f2e119 100644 --- a/e2e/docker_registry/registry.hcl +++ b/e2e/docker_registry/registry.hcl @@ -28,11 +28,6 @@ job "registry" { min_healthy_time = "4s" } - reschedule { - attempts = 0 - unlimited = false - } - restart { attempts = 0 mode = "fail" diff --git a/e2e/metrics/input/setup.hcl b/e2e/metrics/input/setup.hcl index 2b4e1fc5a..c1f249dee 100644 --- a/e2e/metrics/input/setup.hcl +++ b/e2e/metrics/input/setup.hcl @@ -10,10 +10,6 @@ job "setup-podman-auth" { } group "create-files" { - reschedule { - attempts = 0 - unlimited = false - } restart { attempts = 0 diff --git a/e2e/v3/jobs3/jobs3.go b/e2e/v3/jobs3/jobs3.go index 5088deaa3..67a18bdad 100644 --- a/e2e/v3/jobs3/jobs3.go +++ b/e2e/v3/jobs3/jobs3.go @@ -236,6 +236,7 @@ type Cleanup func() func Submit(t *testing.T, filename string, opts ...Option) (*Submission, Cleanup) { t.Helper() + t.Logf("submitting job: %q", filename) sub := initialize(t, filename) for _, opt := range opts {