rinkudesu / rinkudesu-tags

Microservice for managing tags for links
MIT License
1 stars 0 forks source link

`LinkTag` creation race condition #72

Closed KowalskiPiotr98 closed 1 year ago

KowalskiPiotr98 commented 1 year ago

In https://github.com/rinkudesu/rinkudesu-webui/issues/49 it's assumed that sometimes link-tag assignment will be done at the same time as link and/or tag creation. The current implementation suffers from a race condition in this case, as if link-tag assignment were to happen before link or tag creation, it would fail (see: https://github.com/rinkudesu/rinkudesu-tags/blob/d8492812b892ff688331d4a666406fd988c2cbfa/Controllers/LinkTagsController.go#L29..L36).

The logic should be changed so that either they are added as stub values (must ensure they won't override proper objects that could have been created in the meantime), or waits for the creation (by not handling the message, but that'd block the queue potentially, which is bad).

An alternative option would be to include the details of both link and tag and create them as complete objects if missing, but that would require needlesly sending whole objects twice, so I don't like this way.

KowalskiPiotr98 commented 1 year ago

This issue only actually affects links and can be trivially resolved, since links here only require the id and user info. Tags will never be affected by this, since to create the LinkTag you need to know the tag id, which is assigned by the microservice itself.