tornadoweb/tornado — pull request #1148 by drewmiller (2014-08-13 00:30:29+00:00)
Title: Addressing race condition in SimpleAsyncHTTPClient's _on_timeout()

If you fire off a significant number of fetch requests with SimpleAsyncHTTPClient and some of those requests timeout, you may find yourself with a number of uncaught KeyErrors as a race condition exists. In this case, it seems that some of the self.waiting[] keys are actually promoted into the self.active[], and deleted from self.waiting[]. Under extreme conditions, _on_timeout() can be called nearly-simultaneous with _remove_timeout() with the del self.waiting[key] winnin the race and causing a KeyError to be thrown by _on_timeout().