Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis.Client#XReadUntilResult(): also re-try timeout errors #23

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,19 @@ func (c *Client) XReadUntilResult(ctx context.Context, a *redis.XReadArgs) ([]re
cmd := c.XRead(ctx, a)
streams, err := cmd.Result()
if err != nil {
if errors.Is(err, redis.Nil) {
// We need to retry the XREAD commands in the following situations:
// - If Go Redis returns redis.Nil, it means no data was read from Redis — e.g. when the keys don’t
// exist yet, and we will need to retry the operation again.
//
// - To prevent surpassing Go Redis's internal maximum retries or any other I/O timeouts [^1], it's
// important to set a block timeout greater than zero for the XREAD commands, see the "a.Block" above.
// However, setting a block timeout means that Go Redis will not retry any errors internally and will
// instead return an I/O timeout error when exceeding the timeout. Thus, we need to handle this here and
// retry it again. On the other hand, an I/O timeout could also mean a context.DeadlineExceeded error,
// which is not retryable, so we have to check for context termination by ourselves via ctx.Err().
//
// [^1]: https://github.com/redis/go-redis/issues/2131
if (errors.Is(err, redis.Nil) || retry.Retryable(err)) && ctx.Err() == nil {
oxzi marked this conversation as resolved.
Show resolved Hide resolved
continue
}

Expand Down
Loading