Registry items could get duplicated #335

Closed
opened 2023-02-02 16:14:39 +00:00 by yanchan09 · 1 comment

A friend of mine had issue with the "How to use FoundKey" tutorial reappearing every page load, even after completing the tutorial.

They managed to resolve the issue by calling i/registry/remove endpoint with the tutorial key ~10 times, until NO_SUCH_KEY error.

Frontend fetches the registry keys from i/registry/get-all endpoint, which returns every key only once (keeping only the last entry!). Meanwhile i/registry/set only updates the first entry in the database.

I'm not sure how the registry keys got duplicated in the first place, though... In theory

export default define(meta, paramDef, async (ps, user) => {

has a race condition, where multiple keys could be inserted (not updated), but it shouldn't be able to be triggered that easily (to accumulate 10 duplicate keys).

A friend of mine had issue with the "How to use FoundKey" tutorial reappearing every page load, even after completing the tutorial. They managed to resolve the issue by calling `i/registry/remove` endpoint with the `tutorial` key ~10 times, until `NO_SUCH_KEY` error. Frontend fetches the registry keys from `i/registry/get-all` endpoint, which returns every key only once (keeping only the last entry!). Meanwhile `i/registry/set` only updates the first entry in the database. I'm not sure how the registry keys got duplicated in the first place, though... In theory https://akkoma.dev/FoundKeyGang/FoundKey/src/commit/be30e70344cb2862b4397ce0a5927dfda0014c2d/packages/backend/src/server/api/endpoints/i/registry/set.ts#L25 has a race condition, where multiple keys could be inserted (not updated), but it shouldn't be able to be triggered that easily (to accumulate 10 duplicate keys).
Owner

I think adding a unique constraint (over user, scope, key) is a good idea to disallow the same key getting added multiple times.

I think adding a unique constraint (over user, scope, key) is a good idea to disallow the same key getting added multiple times.
Sign in to join this conversation.
No labels
feature
fix
upkeep
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: FoundKeyGang/FoundKey#335
No description provided.