News for hackers. Stuff that matters.
Re:V8 adds support for top-level await by spraak on Wednesday September 25, 2019 @01:01AM (#21067752)
Can anyone explain this to me, how is it a race condition?
Re:V8 adds support for top-level await by pmontra on Wednesday September 25, 2019 @01:56AM (#21068059)
Two concurrent calls to that code. Both of them get the same balance (100), pass the test and deduct the amount (75), getting to a -50 balance.
Re:V8 adds support for top-level await by pmontra on Wednesday September 25, 2019 @07:02AM (#21069515)
I correct myself. It leads to a 25 balance but possibly a double spend of those 50 dollars in two transactions.

The standard pattern is to use database row locking or calling a stored procedure that performs locking inside. Backend developers typically don't like the second solution but it provides a kind of API. Not to be overlooked if there are multiple services accessing it, especially in a polyglot environment.