Browse files

Change default reconnect behavior

By default we should limit the number of times we attempt to reconnect
to Graphite as well as the number of times we try to send data. By
default we limit to three attempts. If a number less than or equal to
zero is specified in the config file we will retry forever.
  • Loading branch information...
1 parent c7213e4 commit 5e8e8065dde6c9a27f0b68eac0240d63ba4aee98 @davisp davisp committed Nov 21, 2011
Showing with 8 additions and 4 deletions.
  1. +7 −3 bucky/carbon.py
  2. +1 −1 bucky/cfg.py
View
10 bucky/carbon.py
@@ -44,13 +44,15 @@ def connect(self):
log.debug("Connected the debug socket.")
self.sock = DebugSocket()
return
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- while self.max_reconnects > 0:
+ for i in xrange(self.max_reconnects):
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.sock.connect((self.ip, self.port))
log.info("Connected to Carbon at %s:%s" % peer)
return
except socket.error, e:
+ if i+1 >= self.max_reconnects:
+ raise
args = (self.ip, self.port, e)
log.error("Failed to connect to %s:%s: %s" % args)
if self.reconnect_delay > 0:
@@ -68,10 +70,12 @@ def close(self):
def send(self, stat, value, mtime):
mesg = "%s %s %s\n" % (stat, value, mtime)
- while self.max_reconnects > 0:
+ for i in xrange(self.max_reconnects):
try:
self.sock.sendall(mesg)
return
except socket.error, err:
+ if i+1 >= self.max_reconnects:
+ raise
log.error("Failed to send data to Carbon server: %s" % err)
self.reconnect()
View
2 bucky/cfg.py
@@ -22,7 +22,7 @@
graphite_ip = "127.0.0.1"
graphite_port = 2003
-graphite_max_reconnects = 0
+graphite_max_reconnects = 3
graphite_reconnect_delay = 5
full_trace = False

0 comments on commit 5e8e806

Please sign in to comment.