diff --git a/nomad/state/state_store.go b/nomad/state/state_store.go index 0bef7d1aa..b1d157fff 100644 --- a/nomad/state/state_store.go +++ b/nomad/state/state_store.go @@ -122,9 +122,11 @@ RUN_QUERY: // We haven't reached the min-index yet. if minIndex > 0 && index <= minIndex { - if expired := ws.WatchCtx(ctx); !expired { - goto RUN_QUERY + if err := ws.WatchCtx(ctx); err != nil { + return nil, index, err } + + goto RUN_QUERY } return resp, index, nil diff --git a/nomad/state/state_store_test.go b/nomad/state/state_store_test.go index 71f1e9003..306987367 100644 --- a/nomad/state/state_store_test.go +++ b/nomad/state/state_store_test.go @@ -51,7 +51,7 @@ func TestStateStore_Blocking_Timeout(t *testing.T) { defer cancel() _, idx, err := state.BlockingQuery(noopFn, 10, deadlineCtx) - assert.Nil(t, err) + assert.EqualError(t, err, context.DeadlineExceeded.Error()) assert.EqualValues(t, 5, idx) assert.WithinDuration(t, timeout, time.Now(), 5*time.Millisecond) }