From 37549481b693a290c01c7d274d12b09eecde2a38 Mon Sep 17 00:00:00 2001 From: Jarrod Johnon Date: Tue, 30 Sep 2014 11:21:01 -0400 Subject: [PATCH] Fix double connect on logging change When logging was changed from none to full, it would always start and immediately abort connecting to start again. Change this by deciding which connection liveness strategy to use based on how many settings changed. If just logging changes, then connect only if not connected or connecting. If more changes, then skip that kinder strategy and go straight to reconnecting. --- confluent_server/confluent/consoleserver.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/consoleserver.py b/confluent_server/confluent/consoleserver.py index c451ca8c..7b9db555 100644 --- a/confluent_server/confluent/consoleserver.py +++ b/confluent_server/confluent/consoleserver.py @@ -99,7 +99,15 @@ class _ConsoleHandler(object): except KeyError: pass if logvalue in ('full', ''): - self._alwayson() + # if the *only* thing to change is the log, + # then let always on handle reconnect if needed, + # since we want to avoid a senseless disconnect + # if already connected + # if other things change, then unconditionally reconnect + onlylogging = len(nodeattribs[self.node]) == 1 + self._alwayson(doconnect=onlylogging) + if onlylogging: + return else: self._ondemand() if logvalue == 'none': @@ -112,8 +120,10 @@ class _ConsoleHandler(object): return self.logger.log(*args, **kwargs) - def _alwayson(self): + def _alwayson(self, doconnect=True): self._isondemand = False + if not doconnect: + return if not self._console and not self.connectionthread: self._connect() else: