client: fixed a bug where corrupt client state could panic the client (#19972)

This commit is contained in:
Cedric Le Roux
2024-02-14 08:14:11 -08:00
committed by GitHub
parent c1b5850473
commit 994a2b1036
3 changed files with 14 additions and 0 deletions

3
.changelog/19972.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a bug where corrupt client state could panic the client
```

View File

@@ -1876,6 +1876,14 @@ func TestClient_hasLocalState(t *testing.T) {
c.stateDB = cstate.NewMemDB(c.logger)
t.Run("nil Job", func(t *testing.T) {
alloc := mock.BatchAlloc()
alloc.Job = nil
c.stateDB.PutAllocation(alloc)
must.False(t, c.hasLocalState(alloc))
})
t.Run("plain alloc", func(t *testing.T) {
alloc := mock.BatchAlloc()
c.stateDB.PutAllocation(alloc)

View File

@@ -4770,6 +4770,9 @@ func (j *Job) Warnings() error {
// LookupTaskGroup finds a task group by name
func (j *Job) LookupTaskGroup(name string) *TaskGroup {
if j == nil {
return nil
}
for _, tg := range j.TaskGroups {
if tg.Name == name {
return tg