From fb968f58d6fbcd0d972db37c6a16cee92da7bec8 Mon Sep 17 00:00:00 2001 From: Sergey Kizunov Date: Fri, 18 Mar 2016 14:08:48 -0500 Subject: [PATCH] Fix race condition with self.connected on TCP transport There is a race condition that occasionally happens when using the TCP transport. When using the TCP transport, it will fire the `__master_connected` event before returning from tcp.py's `AsyncTCPPubChannel.connect_callback`. What sometimes happens is that the event handler for `__master_connected` is executed before the control is returned to `eval_master` in master.py. If this happens, `self.connected` is not yet defined, since `eval_master` defines it. The event handler for `__master_connected` tries to access the not yet defined `self.connected` and an exception occurs. One possible solution is to use `hasattr` to check if `self.connected` is defined before accessing it in the `__master_connected` handler. However, I think it is cleaner just to set `self.connected = False` in `Minion.__init__`, that way this variable will be defined in all cases and can be relied upon. Signed-off-by: Sergey Kizunov --- salt/minion.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/minion.py b/salt/minion.py index cab8d5004b..c4a47df1be 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -752,6 +752,7 @@ class Minion(MinionBase): self._running = None self.win_proc = [] self.loaded_base_name = loaded_base_name + self.connected = False if io_loop is None: if HAS_ZMQ: @@ -1837,7 +1838,7 @@ class Minion(MinionBase): if start: self.sync_connect_master() - if hasattr(self, 'connected') and self.connected: + if self.connected: self._fire_master_minion_start() log.info('Minion is ready to receive requests!')