What happened in the socket close, Rst,pipe signal error

Source: Internet
Author: User
Tags socket error

1, server side close, client side write, causing the server side send RST (server closed socket): The other side has been closed or abnormal termination, but the client side, do not know, this becomes half open

When the server side is close to the socket, assume that there is no data at the server side of the accept buffer. Then close sends the FIN sub-section, client side if received fin, call the Read function, is returned 0, because Fin received, indicating that the client end no data can be received, because the release of FIN, it indicates that the other party is not sending data.

Then the client sends a Reply ACK message indicating that the FIN message is received and the server receives an ACK message, then goes into the fin_wait_2 stage, and according to the TCP protocol, it is not a problem to write data to a service TCP (ACK-Response FIN section) in a fin_wait2 state , so at this point we can call the write function on the client side, write to the client side of the send buffer, by the TCP connection, sent to the server's receive buffer. But at this point, because the server side has closed the socket, so the content of the receive buffer at this time is discarded, and the server side returned RST

The client side of the RST is received, and if the read function is called, it is returned with the RST error:

If our client fails to handle this RST error and continues to call write, a epipe error will occur.

This typically occurs when the client process ignores (or does not handle) the Socket error and continues to write more data to the service TCP, the kernel sends a sigpipe signal to the client process, which by default causes the process to terminate (at which point the foreground process does not have a core dump). In conjunction with the Econnreset error above, it is not a problem to write to a service TCP with an fin_wait2 state (an ACK in response to a FIN section), but it is an error to write a Socket that has received the RST.

The action taken at one end of the RST packet received:

Exception closing a connection has two advantages for an application:

(1) Discard any outgoing data that is meaningless and immediately send the RST message segment;

(2) The receiver of the RST uses the closing method to distinguish between an abnormal shutdown or a graceful shutdown (by the return value of the read operation, a normal return read byte or a blockage, and the return error of the RST).

It is important to note that the RST message segment does not cause any response at the other end (without sending an ACK Response section) and the other end does not confirm at all. The party that receives the RST terminates the connection. The program behaves as follows:

Under the blocking model, the kernel cannot proactively notify the application layer of an error, and the kernel will use an error to notify the application tier-to-end RST only if the application layer invokes read () or write () as an IO system call.

In a non-blocking model, select or Epoll will return SOCKFD readable, and read () will error RST when the application layer reads it.

2, server-side close socket, at this time the server side of the receive buffer has data, is not read, then the server sends the RST to the client side, the receiving buffer data loss, server servers early shutdown socket

3. To a port connection request that does not exist

The client initiates a connection request, sends a SYN message, and sends an RST to Cllient because the server-side socket does not have a listen port

4. Actively open connect () at the same time

5. Actively close the close () at the same time

What happened in the socket close, Rst,pipe signal error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.