]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-71936: Fix race condition in multiprocessing.Pool (GH-124973) (GH-126869)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 15 Nov 2024 14:05:14 +0000 (15:05 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Nov 2024 14:05:14 +0000 (14:05 +0000)
commit7be8743bd120271a4e0101aa575d357b9962e809
tree7f6695c06287d469f8e09b947cd9321aa63a63d9
parentecda3ae2a51cdec65996005690391172bc25ca4b
[3.13] gh-71936: Fix race condition in multiprocessing.Pool (GH-124973) (GH-126869)

Proxes of shared objects register a Finalizer in BaseProxy._incref(), and it
will call BaseProxy._decref() when it is GCed. This may cause a race condition
with Pool(maxtasksperchild=None) on Windows.

A connection would be closed and raised TypeError when a GC occurs between
_ConnectionBase._check_writable() and _ConnectionBase._send_bytes() in
_ConnectionBase.send() in the second or later task, and a new object
is allocated that shares the id() of a previously deleted one.

Instead of using the id() of the token (or the proxy), use a unique,
non-reusable number.

(cherry picked from commit ba088c8f9cf7163b0f28c507cb1343befe21997e)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Akinori Hattori <hattya@gmail.com>
Lib/multiprocessing/managers.py
Misc/ACKS
Misc/NEWS.d/next/Library/2022-10-15-10-18-20.gh-issue-71936.MzJjc_.rst [new file with mode: 0644]