[SOLVED, EBKAC] NAMESPACE.put() fails / hangs just today?


After a fun day of wrangling and adjusting for all the new changes (thanks!), I think I’ve hit my first legit bug. Hopefully, I’m still overlooking something…

I have a KV namespace, passed to my Worker as CACHE. I populated CACHE with a template schema (if that’s the right word…) via the curl API. Reads back just fine with curl. Also, CACHE.get()s work as expected in my Worker.

However, When I go to add data to this namespace, it either hangs or crashes. IOW, I don’t get ■■■■ back… :-/ This is not in the sandbox, this is a live worker with a live KV, being called by a real app (well, “real” means real, not production)

I’ve checked that the KV is attached to the script, the script is attached to the route. Everything else works as expect. What am I missing?



Hey Jason! Could you post your code (or just the part that writes), that way I can help you out.

1 Like


Sure, no problem. But first, a quick update. It’s definitely something wrong with my code. I wrote a separate script and attached it to a /test endpoint. With that, I was able to successfully write to the namespace in question via my Worker. I was also able to confirm the presence of the new key and that the value was the body I had sent to my Worker using the curl API. Here’s test.js:

addEventListener('fetch', event => {

 * Fetch and log a request
 * @param {Request} request
async function handleRequest(request) {
  console.log('Got request', request)
  const rayid = request.headers.get("cf-ray")
  await CACHE.put(rayid, request.body)
  return new Response('done')

So, that works fine. Now, here’s the code that doesn’t work.

/* ... */
    e.waitUntil(logit(`DEBUG2: 002`))

    /* store the raw receipt data for the user */
    var key = `${userGUID}/latestReceiptData`
    e.waitUntil(CACHE.put(key, receiptData))

    e.waitUntil(logit(`DEBUG2: 003`))
    e.waitUntil(CACHE.put(`${userGUID}/latestDecodedReceiptData`, JSON.stringify(receipt)))

    e.waitUntil(logit(`DEBUG2: 004`))
/* ... */

As you might be able to tell, I’m just an old-school C programmer… :slight_smile: .
A few notes:

  • My logit() command has been working fine wrapped in e.waitUntil()
  • I’ve tried CACHE.put() without e.waitUntil(), with await instead, no dice
  • All previous CACHE.get()s work as expected, no issue

Here’s the relevant messages from my log server:

1559736979.684: IAD: 4e2213ba5c83579f: INFO: Version: v0.3-39-g356b85a7d680-dirty
1559736979.684: IAD: 4e2213ba5c83579f: INFO: /verifyReceipt called by: 2607:fb90:d628:d570:99b6:2604:18ee:21
1559736981.083: IAD: 4e2213ba5c83579f: DEBUG: New user f642d980-bad5-4eda-b7ca-89d679f28b13
1559736981.548: IAD: 4e2213ba5c83579f: DEBUG2: 002
1559736981.548: IAD: 4e2213ba5c83579f: DEBUG: New device cad87345-cd51-4c7d-a60f-b312cefb6231
1559736981.548: IAD: 4e2213ba5c83579f: DEBUG2: 001

The out-of-ordering is expected, I’ve not put any effort into tagging the messages so that my log server can reconstruct the order. So it’s just multiple independent calls being racy.

I’m almost certain that I’m doing something dumb. I just can’t nail down what it is.


1 Like

So from what I can piece together:

event.waitUntil(CACHE.put("key","value")) // should always work
event.waitUntil(logit(...)) // only reason it wouldn't write is if the put promise is not getting awaited?

Another thing to consider is: are you writing to the same key frequently?

Update: I fixed it. Yes, it was something stupid. :-/ . The proper reference to the value I want to store was body.receiptData rather than receiptData. Doh! It’s always the obvious ■■■■ that’ll humble you.

Thanks for the help!


1 Like