AppSec Blog

AppSec Blog

Top 25 Series - Rank 25 - Race Conditions

Flying a lot, it happens once in a while that I arrive at the airport early enough to be offered to check in on an earlier flight. Usually the check-in Kiosk offers the option and lists the flight. Last year, I tried to took advantage of this offer, only to be told that the fligt was no longer available after selecting the earlier flight.

Well, not a big deal. I went to the gate, and waited for the later flight. As I tried to board it, my boarding pass in hand, I was told that there was no record of my reservation for this flight.

So what had happened? In this case, I can only speculate. But likely, a race condition occurred. Someone was being added to the earlier flight just as I was added. But before the system was able to check that my seat was actually available, I was removed from the later flight. Finally, as the change failed, the system "forgot" to place me back on the later flight.

Race conditions are very common in shared applications like web applications. Several users may try to order a limited resource. However, race conditions are not uncommon in other applications. For example in accounting, an account may be over drawn by deducting money multiple times before the balance has been adjusted.

Detecting and fixing race conditions is difficult. Usually, race conditions escape traditional testing as they frequently require multiple users to issue requests just at the wrong time, or one user sending requests carefully timed, sometimes multiple requests at exactly the same time.

This issue is usually best solved during the architecture and design phase. Critical functions that may be subject to race conditions need to be identified. Once identified, the functions can be isolated and by using techniques like proper database transactions, it is possible to isolate these operations sufficiently and roll them back completely if they should fail at any point.

3 Comments

Posted March 26, 2010 at 5:53 PM | Permalink | Reply

Karim Said

Race conditions and deadlocks are definitely some of the most difficult issues to resolve during the development. What's worse is that if these issues aren't identified in the design and architecture phase, developers tend to fall back on unnecessarily complicated thread sychronization "solutions" that just end up making code spaghetti.

Posted March 26, 2010 at 5:56 PM | Permalink | Reply

Karim Said

And just so my last comment doesn't seem like all moan and groan, I'll add my constructive two cents: I've found K-maps to be really helpful during the design and arch phase for identifying and eliminating potential sync issues :)

Posted April 06, 2010 at 3:42 PM | Permalink | Reply

Top 25 Series – Summary and Links

[...] 23 – Open Redirect 24 – Use of a Broken or Risky Cryptographic Algorithm 25 – Race Conditions Permalink|Comments RSS Feed - Post a comment|Trackback [...]

Post a Comment






Captcha

* Indicates a required field.