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

🐛 BUG: --experimental-enable-local-persistence stores KV, Durable Objects and Cache data in the same directory #830

Closed
mrbbot opened this issue Apr 21, 2022 · 1 comment · Fixed by #839 or #817

Comments

@mrbbot
Copy link
Contributor

mrbbot commented Apr 21, 2022

What version of Wrangler are you using?

0.0.26-ee3475f

What operating system are you using?

Mac

Describe the Bug

Wrangler 2 sets Miniflare's kvPersist, durableObjectsPersist and cachePersist options to the same string path value when --experimental-enable-local-persistence is enabled:
https://github.com/cloudflare/wrangler2/blob/9d04a6866099e77a93a50dfd33d6e7707e4d9e9c/packages/wrangler/src/dev/local.tsx#L175-L182
This means KV namespaces, Durable Objects, or caches using the same name will share data.


As an example, consider the following worker:

// index.js
export default {
  async fetch(request, env, ctx) {
    const cache = await caches.open("test");
    await cache.put(
      "http://localhost",
      new Response("body", { headers: { "Cache-Control": "max-age=3600" } })
    );
    const { keys } = await env.test.list();
    return new Response(JSON.stringify(keys));
  },
};
# wrangler.toml
main = "index.js"
compatibility_date = "2022-04-21"
kv_namespaces = [
    { binding = "test", id = "_", preview_id = "__" }
]

This returns the following response, even though no data was written to the test KV namespace:

[{"name":"http://localhost/","expiration":1650553706,"metadata":{"status":200,"headers":[["cache-control","max-age=3600"],["content-type","text/plain;charset=UTF-8"]]}}]

Running tree shows the problem here:

$ tree
.
├── index.js
├── wrangler-local-state
│   └── test
│       └── http
│           ├── localhost_
│           └── localhost_.meta.json
└── wrangler.toml

The test directory is being shared by the KV namespace and the cache.


A solution here is to put KV namespaces, Durable Objects and caches in their own subdirectories, by adding a unique path segment to the end of localPersistencePathOrDisableLocalPersistence for each of kvPersist, durableObjectsPersist and cachePersist.

@mrbbot mrbbot added the bug label Apr 21, 2022
@threepointone
Copy link
Contributor

good catch! we'll fix this. thank you for reporting!

threepointone added a commit that referenced this issue Apr 24, 2022
With `--experimental-enable-local-persistence` in `dev`, we were clobbering a single folder with data from kv/do/cache. This patch gives individual folders for them. It also enables persistence even when this is not true, but that stays only for the length of a session, and cleans itself up when the dev session ends.

Fixes #830
threepointone added a commit that referenced this issue Apr 25, 2022
With `--experimental-enable-local-persistence` in `dev`, we were clobbering a single folder with data from kv/do/cache. This patch gives individual folders for them. It also enables persistence even when this is not true, but that stays only for the length of a session, and cleans itself up when the dev session ends.

Fixes #830
threepointone added a commit that referenced this issue Apr 25, 2022
…839)

With `--experimental-enable-local-persistence` in `dev`, we were clobbering a single folder with data from kv/do/cache. This patch gives individual folders for them. It also enables persistence even when this is not true, but that stays only for the length of a session, and cleans itself up when the dev session ends.

Fixes #830
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants