Handling KV Get failures

I’ve written a worker that depends on pulling some small data from KV in order to route traffic to various backends.

Under load, I’ve seen a small percentage of errors that I believe are due to KV gets failing. Unfortunately I can’t easily recreate this scenario and I don’t have a logging pipeline setup yet, so my ability to see what’s happening is limited.

What I’ve done is something like this:

try { 
    data = await KVSTORE.get(`${key}`);
}
catch {
    return new Response('Server Error: 1001', { status: 520 })
}

And I do see a small number of 520 in my logs. Of course this could be a 520 for a difference reason. I’m thinking about adding a retry, but should this be necessary? I don’t see anything in the docs about doing things like this.

From the doc (https://developers.cloudflare.com/workers/reference/storage/reading-data/):

Return Value

The .get method returns a promise which resolves with either the value of your key with the type requested, or null if that key is not in the Namespace.

While the limits say “* Unlimited (100k+) reads per second per key” and I don’t believe I’m hitting anything like that.

How many KV.gets per script do you have?

I have a maximum of three KV gets per script.

Basically I look for a most specific to least specific path (max depth 2) with a default. I could simplify this to a single get if that’s the issue.

It shouldn’t fire the error. have you submitted a ticket to support?

Yeah, I’ll post back if I learn anything useful.

-David