Skip to content

Commit 30ff674

Browse files
aozmekikmiss-islington
authored andcommitted
[3.15] gh-161712: Read the clock once in ThreadHandle_join() (GH-161771)
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. (cherry picked from commit 88d137a) Co-authored-by: Ahmed Semih Özmekik <ahmed-semih@outlook.com>
1 parent 83b1e74 commit 30ff674

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
@@ -541,7 +541,8 @@ ThreadHandle_join(ThreadHandle *self, PyTime_t timeout_ns)
541541
if (deadline) {
542542
// _PyDeadline_Get will return a negative value if the deadline has
543543
// been exceeded.
544-
timeout_ns = Py_MAX(_PyDeadline_Get(deadline), 0);
544+
timeout_ns = _PyDeadline_Get(deadline);
545+
timeout_ns = Py_MAX(timeout_ns, 0);
545546
}
546547

547548
if (timeout_ns) {

0 commit comments

Comments
 (0)