diff --git a/salt/minion.py b/salt/minion.py index 8c7180ff1067..c3690b39ca4a 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -1593,18 +1593,25 @@ def handle_event(self, package): if self.opts['master_type'] == 'failover': log.info('Trying to tune in to next master from master-list') + if hasattr(self, 'pub_channel'): + self.pub_channel.on_recv(None) + if hasattr(self.pub_channel, 'close'): + self.pub_channel.close() + del self.pub_channel + # if eval_master finds a new master for us, self.connected # will be True again on successful master authentication - self.opts['master'] = self.eval_master(opts=self.opts, - failed=True) + master, self.pub_channel = yield self.eval_master( + opts=self.opts, + failed=True) if self.connected: + self.opts['master'] = master + # re-init the subsystems to work with the new master log.info('Re-initialising subsystems for new ' 'master {0}'.format(self.opts['master'])) - del self.pub_channel - self._connect_master_future = self.connect_master() - self.block_until_connected() # TODO: remove self.functions, self.returners, self.function_errors = self._load_modules() + self.pub_channel.on_recv(self._handle_payload) self._fire_master_minion_start() log.info('Minion is ready to receive requests!') @@ -1813,6 +1820,8 @@ def destroy(self): self._running = False if hasattr(self, 'pub_channel'): self.pub_channel.on_recv(None) + if hasattr(self.pub_channel, 'close'): + self.pub_channel.close() del self.pub_channel if hasattr(self, 'periodic_callbacks'): for cb in six.itervalues(self.periodic_callbacks): diff --git a/salt/transport/tcp.py b/salt/transport/tcp.py index 8beec9d2b778..3ff1d4b7f2cb 100644 --- a/salt/transport/tcp.py +++ b/salt/transport/tcp.py @@ -426,6 +426,10 @@ def close(self): # 'StreamClosedError' when the stream is closed. self._read_until_future.exc_info() self._tcp_client.close() + # Clear callback references to allow the object that they belong to + # to be deleted. + self.connect_callback = None + self.disconnect_callback = None def __del__(self): self.close() diff --git a/salt/utils/schedule.py b/salt/utils/schedule.py index 13c6dc06517f..91fcb47af314 100644 --- a/salt/utils/schedule.py +++ b/salt/utils/schedule.py @@ -642,9 +642,11 @@ def handle_func(self, func, data): except OSError: log.info('Unable to remove file: {0}.'.format(fn_)) - try: - salt.utils.daemonize_if(self.opts) + # Don't *BEFORE* to go into try to don't let it triple execute the finally section. + salt.utils.daemonize_if(self.opts) + # TODO: Make it readable! Splt to funcs, remove nested try-except-finally sections. + try: ret['pid'] = os.getpid() if 'jid_include' not in data or data['jid_include']: