Skip to content

Ingress store returns nil after exhausting optimistic-lock retries; UpdateIngress/DeleteIngress panic on missing state #5048

Closed

Description

@da1suk8

Describe the bug

Two defects in the ingress persistence path, same area as #4806.

1. storeIngress / storeIngressState return nil after losing the optimistic lock 5 times

Both retry a WATCH/MULTI/EXEC transaction maxRetries (5) times on redis.TxFailedErr, then fall through to return nil:

// Retry if the key has been changed.
for range maxRetries {
err := s.rc.Watch(s.ctx, txf, IngressKey)
switch err {
case redis.TxFailedErr:
// Optimistic lock lost. Retry.
continue
default:
return err
}
}
return nil
}

// Retry if the key has been changed.
for range maxRetries {
err := s.rc.Watch(s.ctx, txf, IngressStatePrefix+ingressId)
switch err {
case redis.TxFailedErr:
// Optimistic lock lost. Retry.
continue
default:
return err
}
}
return nil
}

A lost update is reported as success:

  • CreateIngress returns an IngressInfo that is not in the ingress hash and whose stream key is not registered.
  • StoreIngress continues to storeIngressState, leaving an orphan {ingress}_state:<id> key with no TTL (L661) that DeleteIngress can never reach.
  • UpdateIngressState / UpdateIngress drop the write without a log line.

storeIngress watches the whole ingress hash, so any ingress create/update on any node between WATCH and EXEC invalidates the attempt. A burst of short-lived ingresses (the workload in #4806) is enough.

2. UpdateIngress / DeleteIngress panic on an ingress without a state key

LoadIngress returns the info with State == nil when the state key is missing (L741-L743). #4806 guarded IOInfoService.UpdateIngressState; the two Twirp handlers still dereference info.State.Status:

switch info.State.Status {

switch info.State.Status {

The panic is recovered by negroni.NewRecovery(), so the node stays up, but the request fails with 500 and the ingress can never be updated or deleted through the API. Such an ingress is produced by the #4806 race, or by (1) when the state write is the one that fails after the info landed.

Server

  • master 704c3280; the lines date from 2022, so every release including v1.13.10.
  • Local dev, single node, Redis 7.

To Reproduce

Regression tests from the fix branch, run on master:

  • TestIngressStoreReportsLostOptimisticLock: a go-redis hook writes to the watched key from a second connection after every WATCH, so all five attempts fail with TxFailedErr deterministically. StoreIngress and UpdateIngressState return nil; afterwards HGET ingress <id> is nil and EXISTS {ingress}_state:<id> is 1 with TTL -1.
  • TestIngressAPIWithNilState: a fake store returns an info with nil State. UpdateIngress panics at ingress.go:318, DeleteIngress at :401.

The hook forces the worst case; in production the trigger is contention on the ingress hash. The defect itself is deterministic once the retries are exhausted.

Expected behavior

Fix is 2 lines plus the #4806 guard in two places; PR with both tests follows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions