Skip to content

Canceled Context with go-redis results in ErrOnlyCachedRecords #38

@quoral

Description

@quoral

Describe the bug
When calling sturdyc.GetOrFetchBatch with Distributed storage enabled, with a cancelled context, the behavior becomes quite unexpected. We have a minimally extended implementation on top of "github.com/redis/go-redis/v9" that we use.
The call ends up returning ErrOnlyCachedRecords, with an empty response. As we use the cache for now as a fallback instead of a real cache, we use the ErrOnlyCachedRecords as a signal that we can just re-use the value from the cache.

A context being done or cancelled in this case implies that we don't care about the response anyway, but due to this error in particular getting ignored by a

value, err := sturdyc.GetOrFetchBatch(ctx, client, keys, keyFunc, getConstantValue)
if errors.Is(err, sturdyc.ErrOnlyCachedRecords) {
	fmt.Println("Only cached records are available")
        return value, nil
}

We see unexpected error logs popping up in the errors logs (without user impact of course as the client is already gone with the context.Cancelled).

Expected behavior
Expected that the error should be one indicating that there was no response (ErrMissingRecord)? Or that the cache returns context.Cancelled.

To Reproduce
I creted a not-so-minally reproducing case for this issue
https://gist.github.com/quoral/dfdc44432aeea566255a5d2f27a80b56

Additional context
Potentially this does not belong in this repository, and should instead be a bug report towards go-redis. However, I lack knowledge of the innards of sturdyc, so wanted to ensure we track that part first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions