Closed happy-river closed 3 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
Or just don't post controversial stuff. :P
Banning people with broken mouses that double-click everything works too
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.
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.
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
ordownvotes
. One comment I examined hasupvotes
set to -2 anddownvotes
set to 2, and three relatedSubPostCommentVote
entries, two withpositive
set to 1 and one withpositive
set to 0.