[New-bugs-announce] [issue42513] Socket.recv hangs

Barney Stratford report at bugs.python.org
Mon Nov 30 06:55:49 EST 2020


New submission from Barney Stratford <barney_stratford at fastmail.fm>:

import socket
self.__socket = socket.create_connection ([host, port], 10000)
value = self.__socket.recv (4096)

This code sometimes hangs despite having a non-None timeout specified. GDB says:

(gdb) bt
#0  0x76d33c94 in __GI___poll (fds=0x7ea55148, nfds=1, timeout=10000)
    at ../sysdeps/unix/sysv/linux/poll.c:29
#1  0x001e8014 in poll (__timeout=<optimized out>, __nfds=<optimized out>, 
    __fds=<optimized out>, __fds=<optimized out>, __nfds=<optimized out>, 
    __timeout=<optimized out>)
    at /usr/include/arm-linux-gnueabihf/bits/poll2.h:46
#2  internal_select (writing=writing at entry=0, interval=<optimized out>, 
    connect=0, connect at entry=4156908, s=<optimized out>)
    at ../Modules/socketmodule.c:745
#3  0x001ec588 in sock_call_ex (s=s at entry=0x76979d68, writing=writing at entry=0, 
    sock_func=sock_func at entry=0x1e736c <sock_recv_impl>, data=0x7ea551b0, 
    data at entry=0x7ea551a8, connect=connect at entry=0, err=err at entry=0x0, 
    timeout=10000000000) at ../Modules/socketmodule.c:840
#4  0x001ed394 in sock_call (data=0x7ea551a8, func=0x1e736c <sock_recv_impl>, 
    writing=0, s=0x76979d68) at ../Modules/socketmodule.c:3287
#5  sock_recv_guts (s=s at entry=0x76979d68, cbuf=<optimized out>, 
    len=<optimized out>, flags=<optimized out>)
    at ../Modules/socketmodule.c:3287
#6  0x001ed51c in sock_recv (s=0x76979d68, args=<optimized out>)
    at ../Modules/socketmodule.c:3318

Googling for this problem turned up this:

https://stackoverflow.com/questions/56038224/poll-waits-indefinitely-although-timeout-is-specified

If we look at socket module.c line 756 (Python 3.7.9 version), we see that we're indeed not checking for the pollfd.revents, and are therefore missing socket errors.

PR coming up in a few days.

----------
components: Library (Lib)
messages: 382145
nosy: Barney Stratford
priority: normal
severity: normal
status: open
title: Socket.recv hangs
type: crash
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42513>
_______________________________________


More information about the New-bugs-announce mailing list