Skip to content

Commit fd9c0ba

Browse files
committed
[3.15] gh-161712: Read the clock once in ThreadHandle_join()
Py_MAX() evaluated _PyDeadline_Get() twice. If the deadline passed between the two calls, the negative second value was used as the timeout, which means no timeout, and Thread.join(timeout) could block forever. main already reads it once since gh-157495.
1 parent be7dbf9 commit fd9c0ba

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix :meth:`threading.Thread.join` with a timeout blocking forever when the
2+
deadline passed between the two reads of the clock used to compute the time
3+
left.

‎Modules/_threadmodule.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
571571
if (deadline) {
572572
// _PyDeadline_Get will return a negative value if the deadline has
573573
// been exceeded.
574-
timeout_ns = Py_MAX(_PyDeadline_Get(deadline), 0);
574+
timeout_ns = _PyDeadline_Get(deadline);
575+
timeout_ns = Py_MAX(timeout_ns, 0);
575576
}
576577

577578
if (timeout_ns) {

0 commit comments

Comments
 (0)