@@ -379,9 +379,7 @@ def get_best_stashcache():
379379 caches_list = json .loads (f .read ())
380380 f .close ()
381381
382- # Get the possible GeoIP sites
383-
384- # Format the caches for the CVMFS query
382+ # Format the caches for the GeoIP query
385383 caches_string = ""
386384 usable_caches = []
387385 for cache in caches_list :
@@ -405,9 +403,9 @@ def get_best_stashcache():
405403
406404 # Randomize the geo ip sites
407405 random .shuffle (geo_ip_sites )
408- found = False
406+ order_str = ''
409407 i = 0
410- while found == False and i < len (geo_ip_sites ):
408+ while order_str == '' and i < len (geo_ip_sites ):
411409 cur_site = geo_ip_sites [i ]
412410 headers ['Host' ] = cur_site
413411 for ip in get_ips (cur_site ):
@@ -420,25 +418,26 @@ def get_best_stashcache():
420418 response = urllib2 .urlopen (req , timeout = 10 )
421419 if response .getcode () == 200 :
422420 logging .debug ("Got OK code 200 from %s" , cur_site )
423- found = True
421+ order_str = response .read ()
422+ response .close ()
424423 break
424+ response .close ()
425425 except urllib2 .URLError , e :
426426 logging .debug ("URL error: %s" , str (e ))
427427 except Exception , e :
428428 logging .debug ("Error: %s" , str (e ))
429429 i += 1
430430
431- if found == False :
431+ if order_str == '' :
432432 # Unable to find a geo_ip server to use, return random choice from caches!
433433 minsite = random .choice (caches_list )
434434 logging .error ("Unable to use Geoip to find closest cache! Returning random cache %s" , minsite )
435435 return minsite
436436 else :
437-
438- # From the response, should respond with something like:
437+ # The order string should be something like:
439438 # 3,1,2
440- ordered_list = response . read () .strip ().split ("," )
441- logging .debug ("Got response %s" , str (ordered_list ))
439+ ordered_list = order_str .strip ().split ("," )
440+ logging .debug ("Got order %s" , str (ordered_list ))
442441 minsite = caches_list [int (ordered_list [0 ])- 1 ]['name' ]
443442
444443 logging .debug ("Returning closest cache: %s" , minsite )
0 commit comments