Skip to content

Return an error when the ingress store exhausts its retries; tolerate missing state in UpdateIngress/DeleteIngress - #5049

Merged
biglittlebigben merged 5 commits into
livekit:masterfrom
da1suk8:fix/ingress-store-lost-update
Oct 26, 2026
Merged

biglittlebigben merged 5 commits into
livekit:masterfrom
da1suk8:fix/ingress-store-lost-update

Conversation

@da1suk8

@da1suk8 da1suk8 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5048

Problem

RedisStore.storeIngress / storeIngressState return nil after losing their optimistic lock maxRetries times, so a lost update is reported as success: CreateIngress returns a phantom ingress, an orphan {ingress}_state:<id> key is left behind, state transitions are dropped silently. Separately, IngressService.UpdateIngress / DeleteIngress panic when LoadIngress returns an info without state, the case #4806 fixed only in IOInfoService.UpdateIngressState.

Change

One commit per defect.

  1. pkg/service/redisstore.go: after the retry loop, return an error wrapping redis.TxFailedErr instead of nil. CreateIngress now fails instead of returning an ingress that was never written, StoreIngress stops before creating the orphan state key, and a dropped UpdateIngressState reaches the caller's existing error log.
  2. pkg/service/ingress.go: the Fix nil pointer dereference in IOInfoService.UpdateIngressState on concurrent DeleteIngress #4806 guard applied to the two Twirp handlers, treating a nil State as empty. UpdateIngress then applies and stores the request; DeleteIngress deletes without calling the ingress service.
  3. pkg/service/redisstore.go: UpdateIngress now fails with ErrIngressNotFound when the ingress no longer exists, checked inside the WATCH on the ingress hash so a later delete fails the EXEC. Without it an update racing a DeleteIngress recreated the deleted ingress and its stream key; this was possible before this PR whenever the delete landed after LoadIngress, and the guard in 2 widened the window to the gap between its two reads.

The guard stays at the call sites to match #4806 and keep API responses unchanged. Normalizing in RedisStore.LoadIngress would also cover ListIngress (state: {} instead of omitted); happy to move it if preferred.

Tests

  • TestIngressStoreReportsLostOptimisticLock: a go-redis hook writes to the watched key from a second connection after every WATCH, so every attempt fails with TxFailedErr deterministically. Asserts the error, that nothing was written, and that no state key is left behind. Needs Redis like the other RedisStore tests.
  • TestIngressAPIWithNilState: panics at ingress.go:318 / :401 on master, passes with the fix.
  • TestUpdateIngressDoesNotRecreateDeletedIngress: delete between load and update; the update fails with ErrIngressNotFound and neither the ingress, its stream key nor its room membership reappears.

go test -race ./pkg/service/... and golangci-lint v2.14.0 pass locally against Redis 7.

@da1suk8
da1suk8 requested a review from a team as a code owner October 23, 2026 14:11
devin-ai-integration[bot]

This comment was marked as resolved.

- a DeleteIngress landing after the caller's LoadIngress was overwritten by the update, bringing the ingress and its stream key back
Comment thread pkg/service/redisstore.go Outdated
}

return nil
return errors.Wrapf(redis.TxFailedErr, "could not store ingress %s after %d attempts", info.IngressId, maxRetries)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a psrpc.Error here (and below).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2d8aa0c: both retry-exhausted returns are now psrpc.NewError(psrpc.Aborted, ...) wrapping the original error, so the code reaches twirp/psrpc clients and errors.Is(err, redis.TxFailedErr) still holds for the tests.

Comment thread pkg/service/redisstore.go Outdated
}

return nil
return psrpc.NewError(psrpc.Aborted, errors.Wrapf(redis.TxFailedErr, "could not store ingress %s after %d attempts", info.IngressId, maxRetries))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning a 5xx error, such as psrpc.Unavailable would be more appropriate here (and below) as an indication to retry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to psrpc.Unavailable in 51cc07e, both here and in storeIngressState. 

@biglittlebigben
biglittlebigben merged commit b50c7f0 into livekit:master Oct 26, 2026
3 of 6 checks passed
@biglittlebigben

Copy link
Copy Markdown
Contributor

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants