Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make swap impenetrable by concurrency
So, currently, these is still a teeny-tiny chance that on subsequent attachment updates an older update overwrites a newer, if another UPDATE happens between reloading and updating. I've tried preventing that with a database transaction, but I apparently back then didn't understand transactions good because I thought they act like mutexes. The right way to make "check and update" atomic is simply making an UPDATE...WHERE query. Then afterwards we reload the record so that it has the actual attachment value, and then we just check whether the attachment value is our stored file. If it's not, we return nil, so that `Attacher#promote` knows that the swap failed and knows to delete the unused stored file. Hopefully this should now ensure that there are no concurrency issues.
- Loading branch information
Showing
5 changed files
with
14 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters