diff options
author | Tomas Krizek <tkrizek@redhat.com> | 2016-12-05 14:01:01 +0100 |
---|---|---|
committer | Martin Basti <mbasti@redhat.com> | 2016-12-06 12:47:33 +0100 |
commit | a44974cdf8a6c53f2e86dac92aa579ba45f666e4 (patch) | |
tree | e1455344b1ec5738dbdf0d7bca684808e43af4eb | |
parent | 2663a966dad138160a850e6af97c38a88ec83f93 (diff) | |
download | freeipa-a44974cdf8a6c53f2e86dac92aa579ba45f666e4.tar.gz freeipa-a44974cdf8a6c53f2e86dac92aa579ba45f666e4.tar.xz freeipa-a44974cdf8a6c53f2e86dac92aa579ba45f666e4.zip |
ipa-replica-conncheck: fix race condition
When the thread that opens ports would execute notify() before the
original thread could call wait(), the original thread would wait
indefinitely for a notify() call.
https://fedorahosted.org/freeipa/ticket/6487
Reviewed-By: Petr Spacek <pspacek@redhat.com>
-rwxr-xr-x | install/tools/ipa-replica-conncheck | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck index 121f06844..cd1b1385d 100755 --- a/install/tools/ipa-replica-conncheck +++ b/install/tools/ipa-replica-conncheck @@ -297,16 +297,18 @@ class PortResponder(threading.Thread): self._close = False self._close_lock = threading.Lock() self.responder_data = 'FreeIPA' - self.ports_open = threading.Condition() + self.ports_opened = False + self.ports_open_cond = threading.Condition() def run(self): root_logger.debug('Starting listening thread.') for port in self.ports: self._bind_to_port(port.port, port.port_type) - with self.ports_open: + with self.ports_open_cond: + self.ports_opened = True root_logger.debug('Ports opened, notify original thread') - self.ports_open.notify() + self.ports_open_cond.notify() while not self._is_closing(): ready_socks, _socks1, _socks2 = select.select( @@ -462,9 +464,12 @@ def main(): RESPONDER = PortResponder(required_ports) RESPONDER.start() - with RESPONDER.ports_open: - RESPONDER.ports_open.wait() - root_logger.debug('Original thread resumed') + + with RESPONDER.ports_open_cond: + if not RESPONDER.ports_opened: + root_logger.debug('Original thread stopped') + RESPONDER.ports_open_cond.wait() + root_logger.debug('Original thread resumed') remote_check_opts = ['--replica %s' % options.hostname] |