#7595 replication.wait_for_entry() mishandles timeout due to rounding
Closed: fixed Opened by cheimes.

As part of ticket https://pagure.io/freeipa/issue/7593, I refactored replication.wait_for_entry() to support attribute values and a clearer error handling path. After the refactoring, some tests started to fail, because an entry wasn't replicated in a timely fashion. It turned out that the tests have been broken for a while, but replication.wait_for_entry() failed to report it.

Simplified code:

timeout = int(time.time()) + 60
entry = None
while int(time.time()) < timeout:
    try:
        entry = fails()
    except Exception:
        pass
    time.sleep(1)
if entry is None and int(time.time()) > timeout:
    raise NotFound()
elif entry:
    return "ok"

In the false negative test, the loop spent 60.45 seconds. Since int(60.45) == 60 and 60 < 60 is false, the loop terminates with entry still None. But since 60 > 60 is also false, the function never raised NotFound() unless the current time was rounded up. For small timesouts around 60 seconds and a fast LDAP server, this never happened.

See @ftweedal long comment on https://github.com/freeipa/freeipa/pull/2051#issuecomment-399301323


Metadata Update from @cheimes:
- Custom field on_review adjusted to https://github.com/freeipa/freeipa/pull/2051

master:

  • 14c869b347e488e40544ee1e6c4b35341124c76c Improve and fix timeout bug in wait_for_entry()
  • 1b966f708aa33c07f68fc30daaf6e4800a6b4a53 Use common replication wait timeout of 5min
  • ad838c37a9ca2d1c5a2e0becf73ddacb004b3ab6 Fix replication races in Dogtag admin code

ipa-4-6:

  • 735763769855ef01cf34f355a57f35e058d91479 Improve and fix timeout bug in wait_for_entry()
  • 39889882a7b0e5a3dc10208455728e9a678af606 Use common replication wait timeout of 5min
  • 763951c7fd29a8032778b41018cf15d07a88c43b Fix replication races in Dogtag admin code

ipa-4-5:

  • 7e9648736185734fc39752df875321558f4464e4 Improve and fix timeout bug in wait_for_entry()
  • d129cb2ab70f658e4b07e1fbb7f16905c66895e9 Use common replication wait timeout of 5min
  • b763b62069040f3efafc65197063a84411bd4d10 Fix replication races in Dogtag admin code

Metadata Update from @cheimes:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

Metadata