Phuks-co / throat

Open Source link aggregator and discussion platform powering Phuks
https://phuks.co
MIT License
74 stars 32 forks source link

Incorrect upvote and downvote counts #250

Closed happy-river closed 3 years ago

happy-river commented 4 years ago

I don't know how this happens, just that it is happening, and happening as recently as this week. In our busy instance, we currently have 14 comments and one post with a negative number in either upvotes or downvotes. One comment I examined has upvotes set to -2 and downvotes set to 2, and three related SubPostCommentVote entries, two with positive set to 1 and one with positive set to 0.

Polsaker commented 4 years ago

This is a race condition that we've managed to mitigate but not completely eliminate. Happens when two requests change a vote very close one to another. One possible fix is to rate-limit the voting endpoint to maybe 1 request every 0.5sec? The other is to add locks

globalistas commented 4 years ago

Or just don't post controversial stuff. :P

Polsaker commented 4 years ago

Banning people with broken mouses that double-click everything works too

happy-river commented 4 years ago

I dug into the logs on a comment that had negative downvotes and found a user who managed to click upvote 8 times and downvote once in slightly over a second, which supports the race condition explanation.

happy-river commented 4 years ago

Our rate limiter lets you limit things to 2/second but not 1/0.5 seconds, and 2 per second would still allow two requests in rapid succession possibly triggering the race condition. And it would also probably be noticed by people who want to upvote several comments quickly. We could also have the front end vote function limit voting by keeping a map of ids to booleans and using it to prevent a new POST from being sent before the previous one on that comment or post has received a response.