]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/ceph_argparse: avoid int overflow 33101/head
authorKefu Chai <kchai@redhat.com>
Fri, 7 Feb 2020 14:44:53 +0000 (22:44 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 7 Feb 2020 14:44:54 +0000 (22:44 +0800)
in python 2.6.8, `thread.join(timeout)` tries to convert the given
timeout to PyTime, but turns out `2 << 32` overflows when python
runtime converts the timeout from sec to ns. that's why
the `lock.acquire()` call always fail in
`Thread._wait_for_tstate_lock()`.
and we end up with an alive thread after calling `thread.join()`.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/ceph_argparse.py

index 4c65761f51e3214b8f1042803f496f68c791be7f..ab112e794c55a933364f0508538b52c2cdbef677 100644 (file)
@@ -1317,7 +1317,9 @@ def run_in_thread(func, *args, **kwargs):
     if timeout == 0 or timeout == None:
         # python threading module will just get blocked if timeout is `None`,
         # otherwise it will keep polling until timeout or thread stops.
-        timeout = 2 ** 32
+        # wait for INT32_MAX, as python 3.6.8 use int32_t to present the
+        # timeout in integer when converting it to nanoseconds
+        timeout = (1 << (32 - 1)) - 1
     t = RadosThread(func, *args, **kwargs)
 
     # allow the main thread to exit (presumably, avoid a join() on this