sysbatch: fix panic from reschedule block (#26534)

* fix panic from nil ReschedulePolicy

commit 279775082c (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
This commit is contained in:
Daniel Bennett
2025-08-18 10:19:14 -04:00
committed by GitHub
parent 1ae83114c1
commit 2c699b9794
5 changed files with 4 additions and 14 deletions

View File

@@ -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)),