Re: connection failure after "tcp: remove max_qlen_log"

From: Kui Zhang
Date: Sat Feb 27 2016 - 14:58:53 EST


Finally tracked down some additional info:

sock.listen(0) behavior appears to be affected by tcp_syncookies


sysctl -w 'net.ipv4.tcp_syncookies=1'; python lis.py
[/tmp]# telnet 127.0.0.1 42000
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
test
Connection closed by foreign host.


sysctl -w 'net.ipv4.tcp_syncookies=0'; python lis.py
[/tmp]# telnet 127.0.0.1 42000
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection timed out




>>> $ cat lis.py
>>> #!/usr/bin/python
>>>
>>> import socket
>>> sock = socket.socket()
>>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>>> sock.bind(('127.0.0.1',42000))
>>> sock.listen(0)
>>> s, a= sock.accept()
>>>
>>> s.send('test')
>>>
~






On Mon, Jan 25, 2016 at 11:40 PM, Kui Zhang <kuizhang@xxxxxxxxx> wrote:
> I was using 2.7.11.
>
> Older version did set backlog to 1 ( http://bugs.python.org/issue8498 ).
>
>
>
> On Sun, Jan 24, 2016 at 7:18 PM, Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
>> On Sun, Jan 24, 2016 at 2:17 AM, Kui Zhang <kuizhang@xxxxxxxxx> wrote:
>>> We licensed the java software. As far as I can tell, the connection is
>>> for IPC with a child process. There should not be large RTT.
>>>
>>> I will contact vendor regarding to listen(fd,0) issue, on Monday.
>>>
>>> I am not fully convinced, that is the problem. I saw that man page for
>>> listen. However accept() works, in python, with backlog = 0. The java
>>> software works with kernel build one commit before.
>>
>> Note that python (2.4.6 here) translates sock.listen(0) to listen(fd,
>> 1), maybe to avoid surprises on some OS ;)
>>
>> $ cat lis.py
>> #!/usr/bin/python
>>
>> import socket
>> sock = socket.socket()
>> sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
>> sock.bind(('127.0.0.1',42000))
>> sock.listen(0)
>> s, a= sock.accept()
>>
>> s.send('test')
>>
>> $ strace ./lis.py
>> ...
>> close(5) = 0
>> close(4) = 0
>> close(3) = 0
>> futex(0x8d8e460, FUTEX_WAKE, 1) = 0
>> socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
>> setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
>> bind(3, {sa_family=AF_INET, sin_port=htons(42000),
>> sin_addr=inet_addr("127.0.0.1")}, 16) = 0
>> listen(3, 1) = 0
>> accept(3,