graphite-project/graphite-web — pull request #592 by baites (2014-01-16 20:06:53+00:00)
Title: Sync event for connection in remote storage.

This is to fix a problem when using distributed rendering in our graphite cluster. The problem was that there were instances where the connection to fetch metrics was not ready before trying to get the response.

This created an exception such as

Mon Jan 13 11:57:51 2014 :: Error requesting URL
Traceback (most recent call last):
File "/opt/graphite/webapp/graphite/remote_storage.py", line 182, in wait_for_results
response = connection.getresponse()
NameError: free variable 'connection' referenced before assignment in enclosing scope
failing rendering some plots when render metrics from remote servers.

I added a event (connection_event) that is set once the connection is stablished and the GET operation is successful. Parse of the response is delayed until the connection_event is set. The maximum time for that delay is given by REMOTE_FETCH_TIMEOUT.