cloudflare / miniflare

πŸ”₯ Fully-local simulator for Cloudflare Workers. For the latest version, see https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare.
https://miniflare.dev
MIT License
3.78k stars 205 forks source link

Fix `KV#list` with long (β‰₯50ch) prefixes #691

Closed huw closed 1 year ago

huw commented 1 year ago

Resolves #690. See comments for more.

changeset-bot[bot] commented 1 year ago

⚠️ No Changeset found

Latest commit: 0480e821dfb0de26bd4db4e6d359d93ef5ddad04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

mrbbot commented 1 year ago

Hey! πŸ‘‹ Great catch! I suspect we might need some workerd changes to fix this, will flag internally. πŸ‘

huw commented 1 year ago

@mrbbot Is there an issue I can follow? I’m not sure if I made it clear but this completely blocks me from using local mode, which means I can’t adopt the Birthday Week features

huw commented 1 year ago

I narrowed this down to https://github.com/cloudflare/workerd/blob/efa6c737e0aa78af29e353cecc88e05537cb44b3/src/workerd/util/sqlite.c%2B%2B#L526, which sets the LIKE clause limit to 50 characters for security reasons. Unless @kentonv is willing to raise it, I think the easier solution is just to avoid LIKE clauses unless we need complex patterns. As such, I updated the PR to run WHERE SUBSTR(key, 1, LENGTH(:prefix)) = :prefix instead and dropped the escaping code. I can’t see many reasons why it would be slower or otherwise undesirable, but you’ll know this better than I will. Thoughts?

mrbbot commented 1 year ago

Hey! πŸ‘‹ Thank you very much for fixing this, and apologies I didn't get back to you sooner. I asked about this internally, but never followed-up on it. I was going to switch to this exact substr approach if we couldn't get those limits lifted, so very happy with this approach. πŸ˜ƒ Looks like it's still doing an index scan so not concerned about it being slower. πŸ‘

This was also a problem with R2. We're planning to do another patch release today to fix some logging issues. I've committed the required fixes for R2 too, so we can get this in with that. πŸ™‚

huw commented 1 year ago

Goated, cheers mate 🐐