From 711d8761849d2e252ebd72cba0784d0ee067b3ab Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 7 Feb 2020 22:44:53 +0800 Subject: [PATCH] pybind/ceph_argparse: avoid int overflow 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 --- src/pybind/ceph_argparse.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pybind/ceph_argparse.py b/src/pybind/ceph_argparse.py index 4c65761f51e32..ab112e794c55a 100644 --- a/src/pybind/ceph_argparse.py +++ b/src/pybind/ceph_argparse.py @@ -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 -- 2.39.5