2

I was going to get some insight into the impact of changing TCP connection queue size. So I wrote a simple server/client pair to test it.

The server instantiates the ForkingTCPServer in the python module SocketServer. To test the impact of pending connection queue size, I override two parameters of the server as follows:

max_children = 1        # default 40, max number of child processes
request_queue_size = 0  # default 5, socket listen() backlog

Below is the request handler of the server, which provides a simple 'delayed' echo service.

class RequestHandler(socketserver.StreamRequestHandler):
    def handle(self):
        self.data = self.rfile.readline().strip()
        time.sleep(30)
        self.wfile.write(self.data)

In the client, 10 sockets connect the server and send a line at nealy the same time.

for i in xrange(10): 
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sockets.append(s)
    s.connect_ex(address)
    s.sendall('{}\n'.format(i)

The result is only 3-4 sockets got successfully connected. The others didn't even finish the 3-way handshake and finally the server sent a RST to them. Here's the tcpdump output of one of the failed clients. It can be seen that the server(port: 10086) received the SYN from the client(port: 53241) and sent back a SYN/ACK. The client also sent an ACK upon receiving SYN/ACK. However, it seems that the server did not receive the ACK from the client. So it kept sending SYN/ACK to the client and finally gave up by sending a RST.

Can somebody explain to me why the server did not see the ACK? Is it because the connection queue is overflowed?

17:41:30.568077 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [S], seq 3931554775, win 32792, options [mss 16396,sackOK,TS val 2434238 ecr 0,nop,wscale 6], length 0
17:41:30.568090 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2434238 ecr 2434238,nop,wscale 6], length 0
17:41:30.568100 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2434238 ecr 2434238], length 0
17:41:30.568479 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434239 ecr 2434238], length 2
17:41:30.770902 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434440 ecr 2434238], length 2
17:41:31.172453 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2434843 ecr 2434238], length 2
17:41:31.767360 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2435438 ecr 2434843,nop,wscale 6], length 0
17:41:31.767391 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2435438 ecr 2434238], length 0
17:41:31.976349 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2435647 ecr 2434238], length 2
17:41:33.584352 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2437255 ecr 2434238], length 2
17:41:33.969825 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2437640 ecr 2437255,nop,wscale 6], length 0
17:41:33.969854 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2437640 ecr 2434238], length 0
17:41:36.800489 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2440471 ecr 2434238], length 2
17:41:38.177461 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2441848 ecr 2440471,nop,wscale 6], length 0
17:41:38.177493 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2441848 ecr 2434238], length 0
17:41:43.232468 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2446903 ecr 2434238], length 2
17:41:46.193321 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2449864 ecr 2446903,nop,wscale 6], length 0
17:41:46.193352 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2449864 ecr 2434238], length 0
17:41:56.096467 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2459767 ecr 2434238], length 2
17:42:02.211676 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [S.], seq 2946632838, ack 3931554776, win 32768, options [mss 16396,sackOK,TS val 2465882 ecr 2459767,nop,wscale 6], length 0
17:42:02.211698 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [.], ack 1, win 513, options [nop,nop,TS val 2465882 ecr 2434238], length 0
17:42:21.825117 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2485495 ecr 2434238], length 2
17:43:13.281525 IP localhost.localdomain.53241 > localhost.localdomain.10086: Flags [P.], seq 1:3, ack 1, win 513, options [nop,nop,TS val 2536952 ecr 2434238], length 2
17:43:13.281625 IP localhost.localdomain.10086 > localhost.localdomain.53241: Flags [R], seq 2946632839, win 0, length 0
  • The answer to this question will be highly platform-dependent. What operating system, and what version of the OS are you using? – Robᵩ Jan 08 '14 at 17:03

1 Answers1

0

is it because the connection queue was overflowed?

No. If the backlog queue was full it wouldn't send SYN/ACK, it would either do nothing or send a an RST, depending on the platform.

user207421
  • 305,947
  • 44
  • 307
  • 483