Skip to content

Instantly share code, notes, and snippets.

@halcyonardency
Created August 26, 2014 02:27
Show Gist options
  • Save halcyonardency/ef534e48982931eef81c to your computer and use it in GitHub Desktop.
Save halcyonardency/ef534e48982931eef81c to your computer and use it in GitHub Desktop.
Fix for CLUSTER_SERVERS on Graphite-web v0.9.12, on Linux, when net.ipv4.ip_nonlocal_bind = 1 (usually set when using keepalived)
--- storage-orig.py 2014-08-25 19:24:37.357155937 -0700
+++ storage.py 2014-08-25 19:26:04.100154924 -0700
@@ -98,22 +98,18 @@
if ':' in host:
host = host.split(':',1)[0]
- for port in xrange(1025, 65535):
- try:
- sock = socket.socket()
- sock.bind( (host,port) )
- sock.close()
-
- except socket.error, e:
- if e.args[0] == errno.EADDRNOTAVAIL:
- return False
- else:
- continue
-
- else:
- return True
+ try:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ sock.connect( (host, 4242) )
+ local_ip = sock.getsockname()[0]
+ sock.close()
+ except:
+ log.exception("Failed to open socket with %s" % host)
+ raise
+ if local_ip == host:
+ return True
- raise Exception("Failed all attempts at binding to interface %s, last exception was %s" % (host, e))
+ return False
def is_pattern(s):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment