bpo-25920: Remove socket.getaddrinfo() lock on macOS#20177
Conversation
|
This change also impacts socket.getnameinfo() and setipaddr() helper which is used by getsockaddrarg() to parse a "socket address": sock.bind, sock.connect, sock.connect_ex, sock.sendto, sock.sendmsg. I'm not sure if it's worth it to list all impacted methods. With this change, socketmodule.c still uses netdb_lock on platforms which don't provide gethostbyname_r(): |
Sorry, something went wrong.
|
PR rebased to amend the commit messaged to a fix a typo (see previous review comments). |
Sorry, something went wrong.
|
@ronaldoussoren @ned-deily: I plan to merge this PR into master (but not backport it to 3.9) at the end of the week. Do you plan to review it? |
Sorry, something went wrong.
ronaldoussoren
left a comment
There was a problem hiding this comment.
Patch looks good to me, other than a pedantic note for the news entry.
As an aside (not to be addressed in the PR): Apparently gethostbyname() and related functions are thread-safe on macOS. This is according to the manpage on macOS 10.15. I haven't checked in which version that changed. This allows avoiding the use of the gethostbyname lock as well.
Sorry, something went wrong.
ned-deily
left a comment
There was a problem hiding this comment.
If @ronaldoussoren is fine with it, I'm fine with it.
Sorry, something went wrong.
On macOS, socket.getaddrinfo() no longer uses an internal lock to prevent race conditions when calling getaddrinfo(). getaddrinfo is thread-safe is macOS 10.5, whereas Python 3.9 requires macOS 10.6 or newer. The lock was also used on FreeBSD older than 5.3, OpenBSD older than 201311 and NetBSD older than 4.
I chose to restrict my PR to the socket.getaddrinfo() lock on purpose: Would you mind to open a separated issue for gethostbyname()? |
Sorry, something went wrong.
* 'master' of github.com:python/cpython: (497 commits) bpo-40061: Fix a possible refleak in _asynciomodule.c (pythonGH-19748) bpo-40798: Generate a different message for already removed elements (pythonGH-20483) closes bpo-29017: Update the bindings for Qt information with PySide2 (pythonGH-20149) bpo-39885: Make IDLE context menu cut and copy work again (pythonGH-18951) bpo-29882: Add an efficient popcount method for integers (python#771) Further de-linting of zoneinfo module (python#20499) bpo-40780: Fix failure of _Py_dg_dtoa to remove trailing zeros (pythonGH-20435) Indicate that abs() method accept argument that implement __abs__(), just like call() method in the docs (pythonGH-20509) bpo-39040: Fix parsing of email mime headers with whitespace between encoded-words. (pythongh-17620) bpo-40784: Fix sqlite3 deterministic test (pythonGH-20448) bpo-30064: Properly skip unstable loop.sock_connect() racing test (pythonGH-20494) Note the output ordering of combinatoric functions (pythonGH-19732) bpo-40474: Updated coverage.yml to better report coverage stats (python#19851) bpo-40806: Clarify that itertools.product immediately consumes its inpt (pythonGH-20492) bpo-1294959: Try to clarify the meaning of platlibdir (pythonGH-20332) bpo-37878: PyThreadState_DeleteCurrent() was not removed (pythonGH-20489) bpo-40777: Initialize PyDateTime_IsoCalendarDateType.tp_base at run-time (pythonGH-20493) bpo-40755: Add missing multiset operations to Counter() (pythonGH-20339) bpo-25920: Remove socket.getaddrinfo() lock on macOS (pythonGH-20177) bpo-40275: Fix test.support.threading_helper (pythonGH-20488) ...
On macOS, socket.getaddrinfo() no longer uses an internal lock to
prevenet race conditions when calling getaddrinfo(). getaddrinfo is
thread-safe is macOS 10.5, whereas Python 3.9 requires macOS 10.6 or
newer.
The lock was also used on FreeBSD older than 5.3, OpenBSD older than
201311 and NetBSD older than 4.
https://bugs.python.org/issue25920