About TCP connection queue full and half-connection queue

Turn: https://www.toutiao.com/a6721163619758768647/ 

 

There are two concepts of knowledge queue, backlog, tcp_abort_on_overflow like TCP three-way handshake in. Common abnormal connection service there are many other issues such as Connection refused. By understanding this knowledge combined with some help troubleshooting tools to effectively solve some unusual problems connected services appearing on production. The following analysis of these will be discussed.

A, TCP three-way handshake

 

 

 

Handshake

 

  • First: client sends to the server syn handshake
  • Second: server after receiving the reply syn syn + ack to the client while the server is connected to a semi-related information in a queue.
  • Third: After the client receives a server reply syn + ack ack, acknowledged receipt of the syn server of + ack, server client after receiving the ack more different situations be treated differently (which tcp_abort_on_overflow parameters and accept queue about the whole connection queue is full)

 

 

 

Socket three-way handshake state enumeration

  • LISTEN: listens for a connection request from the remote TCP ports
  • SYN-SENT: the connection after sending the connection request matches the request wait
  • SYN-RECEIVED: after receiving a connection request and transmits the connection request acknowledgment wait
  • ESTABLISHED: represents an open connection, data can be transmitted to the user

Two, full and half-connection queue connection queue

 

There are two queues handshake:

  • Full connection queue (accept queue)
  • Semi connection queue (syns queue)

 

Analysis: When the (client when the client reaches the server SYN server) first handshake TCP will not create a new entry in the connection queue is completed, this one will remain in the queue until the connection is not completed third handshake (customer SYN ACK to the server) until the end. If the three-way handshake completed properly, that will never complete the connection queue to the connection end of the queue has been completed. When a process calls accept (), it has completed the connection queue team head entries will be returned to the process.

 

Third, the third server handshake specific approach

 

Scenario 1: When less than full connectivity

当server收到client的ack后会先判断全连接队列accept queue是否已满,如果队列未满则从半连接队列拿出相关信息存放入全连接队列中,之后服务端accept()处理此请求。

场景2:当全连接已满且tcp_abort_on_overflow = 0

server会扔掉client 发过来的ack。之后隔一段时间server会重发握手第二步的syn+ack包给client,如果客户端连接一直排队不上等待超时则会报超时异常。

场景3:全连接已满且tcp_abort_on_overflow = 1时

server会发送一个reset包给client,表示废除这个握手过程和这个连接(客户端会报connection reset by peer异常)

四、关于backlog

backlog表示全连接队列(已连接未处理队列)的大小,该值默认为50。

 

 

当全连接队列满时则会根据tcp_abort_on_overflow的值做出相应的处理方式

 

//Linux查看tcp_abort_on_overflow值
cat /proc/sys/net/ipv4/tcp_abort_on_overflow


五、总结

TCP存在两个队列(全连接队列和半连接队列),第一次握手后TCP会产生的新项并先存放到半连接队列中。当完成三次握手之后项会移动到全连接队列里(全连接队列默认大小backlog值是50)。如果当全连接队列满了server则会根据tcp_abort_on_overflow 的值来做对应的处理,,值为0则丢弃当前客户端的ack,值为1则废弃当前握手过程与连接。

 

Guess you like

Origin www.cnblogs.com/python-xiakaibi/p/12128156.html