Friday, January 11, 2013

How our users exploited concurrency and how we fixed it - Evil Trout's Blog

How our users exploited concurrency and how we fixed it - Evil Trout's Blog: "# Keep everything in a database transaction
Player.transaction do

# Find the player's current goal
goal = player.goal

# Make sure we don't reward goals that have been already been completed
unless goal.completed?
goal.update_column :completed, true
player.increment!(:score, goal.score)
end

end
After much headdesking, I eventually discovered that the above code is not safe under concurrency."

'via Blog this'