Skip to content

fix(storage): cache keys that differ only in case collide on MySQL #284

Closed

Description

@LouisHaftmann

On MySQL, cache entry lookups compare key case-insensitively and accent-insensitively, because the column uses the default utf8mb4_0900_ai_ci collation. Postgres compares exactly, so the same workflow behaves differently depending on which database the server runs on.

Where it shows up

  • Finalizing overwrites another key's entry. In completeUpload (lib/storage.ts, the existingCacheEntry lookup inside the transaction), finalizing foo while a Foo entry exists for the same version, scope and repo repoints Foo at the new data. No foo entry is created.
  • Exact matches cross case. In matchCacheEntry, the exact-primary and restore-key = lookups return a Foo entry when the request asks for foo.
  • Prefix matches also diverge. The prefix LIKE match is case-insensitive on MySQL, and on SQLite for ASCII, but case-sensitive on Postgres.

Uploads themselves are not affected: since #283, uploads is matched by an exact hash of key, version, scope and repo.

Proposed fix

  • Decide on one key semantics for every driver, ideally the one GitHub's cache service uses.
  • If keys should be exact, give the MySQL key columns a binary collation (utf8mb4_bin) in a migration, or compare with BINARY. Then decide whether the prefix LIKE should be case-sensitive on SQLite too.
  • Test: save Foo, then finalize and restore foo, and assert the outcome is the same on all test:matrix DB drivers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions