Description
I wanted to cross-post this bug here because I can't just move it. It's in the Rails code, but all the tech details are already over there.
This deadlock happens because comment (and, much more rarely, story) creation is locking tables in a different order than vote creation (slash updating?). Maybe because of assigning the user's initial upvote or some memoized value like score/karma/votes/number of comments/etc.
The job here is to vote/unvote stories and comments in dev, and read the rails server log for the order that tables are touched in. Then same for story and comment posting. I am almost certain that will uncover tables accessed in a different order. Just posting those notes as a comment here would be very helpful!
If that is indeed the cause of the deadlock, then we have to shlep through the controllers and callbacks to figure out how to reorder, simplify, or break apart the transactions. Probably nothing even needs to be in a transaction, we're just getting it from Rails by default. But since I touched all the score code in 20c1590 I think voting should always work by doing score += 1
or score = sum(votes)
rather than an unsafe select ... add 1 in ruby ... update
, so a transaction is unneeded.