[issue1430] Memory corruption on socket.gethostbyname_ex

New submission from Vasily Evseenko <svpcom@gmail.com>: There are some memory corruption while calling socket.gethostbyname_ex from the thread while other thread executes JIT'ed code: In such case socket.gethostbyname_ex returns random entries from /etc/hosts instead of DNS lookup. Notes from dev-list: --- - it reproduces even without a JIT-enabled pypy - PyPy uses gethostbyname() instead of gethostbyname_r() --- Affected versions: PyPy 1.8, 1.9, 2.0b1 on Linux (Fedora 16, Debian GNU/Linux 6.0) --- Python 2.7.3 (07e08e9c885ca67d89bcc304e45a32346daea2fa, Mar 19 2013, 07:39:19) [PyPy 2.0.0-beta1 with GCC 4.4.5] on linux2 Python 2.7.3 (07e08e9c885ca67d89bcc304e45a32346daea2fa, Dec 18 2012, 05:33:54) [PyPy 2.0.0-beta1 with GCC 4.6.3] on linux2 Python 2.7.2 (2346207d99463f299f09f3e151c9d5fa9158f71b, May 15 2012, 11:08:08) [PyPy 1.8.0 with GCC 4.6.3] on linux2 Python 2.7.2 (341e1e3821fff77db3bb5cdb7a4851626298c44e, Oct 23 2012, 11:37:42) [PyPy 1.9.0 with GCC 4.6.3] on linux2 --- Not affected: PyPy 2.0b1 on MacOSX --- Python 2.7.3 (07e08e9c885ca67d89bcc304e45a32346daea2fa, Mar 19 2013, 07:52:27) [PyPy 2.0.0-beta1] on darwin Python 2.7.3 (7e4f0faa3d51, Nov 21 2012, 15:59:46) [PyPy 2.0.0-beta1 with GCC 4.2.1] on darwin --- ---------- files: test.py messages: 5489 nosy: pypy-issue, svpcom priority: critical release: 2.0 status: unread title: Memory corruption on socket.gethostbyname_ex ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Brian Kearns <bdkearns@gmail.com> added the comment: this is known -- documented in XXX comments in rpython/rlib/rsocket.py. ---------- nosy: +bdk status: unread -> chatting ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Vasily Evseenko <svpcom@gmail.com> added the comment: Are there any way to convert DNS name to list of ip-addresses without external locks on PyPy? ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Brian Kearns <bdkearns@gmail.com> added the comment: try socket.getaddrinfo? ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Vasily Evseenko <svpcom@gmail.com> added the comment: Thanks a lot! ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Armin Rigo <armin.rigo@gmail.com> added the comment: How about fixing the XXXes? Grep for USE_GETHOSTBYNAME_LOCK and USE_GETADDRINFO_LOCK in Module/socketmodule.c from CPython. ---------- nosy: +arigo ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________

Brian Kearns <bdkearns@gmail.com> added the comment: corruption fixed with merge of issue1430 branch in commit 9fe91ecfce83 leaving this open at a lower priority as we probably want to use the thread-safe versions of gethostxxx instead of using locks, when possible. ---------- priority: critical -> performance bug release: 2.0 -> title: Memory corruption on socket.gethostbyname_ex -> gethostbyname_ex should use thread-safe functions rather than locks ________________________________________ PyPy bug tracker <tracker@bugs.pypy.org> <https://bugs.pypy.org/issue1430> ________________________________________
participants (3)
-
Armin Rigo
-
Brian Kearns
-
Vasily Evseenko