lobsters/lobsters

mariadb deadlocks

オープン

#1,238 opened on 2024/01/05

 (4 件のコメント) (0 件のリアクション) (0 人の担当者)Ruby (961 件のフォーク)user submission
buggood first issue

Repository metrics

Stars
 (4,680 個のスター)
PR merge metrics
 (平均マージ 7d 4h) (30d で 20 merged PRs)

説明

https://github.com/lobsters/lobsters/issues/1612

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 20c15907 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.

コントリビューターガイド