[3.15] gh-161712: Read the clock once in ThreadHandle_join()

Merged
AO
5d ago
+5-1

Py_MAX() evaluates _PyDeadline_Get() twice. If the deadline passes between the two calls, the first value passes the > 0 check and the second, negative one becomes the timeout, which PyEvent_WaitTimed() takes as no timeout, so Thread.join(timeout) blocks forever. main has read the clock once since gh-157495 (GH-157591), which wasn't backported because it was a cleanup. This is that hunk, with a NEWS entry.

The window is too small to hit from a test, so I forced it under gdb: a signal wakes the join loop of join(3.0) after a second, and the second clock read in that loop reports the deadline as passed. On 3.15 as it is, the join was still blocked after 30 seconds. With this change it returns after 3 seconds. test_threading and test_thread pass.

  • Issue: gh-161712