2

According to TCP/IP Guide, when a TCP session is closed by the Client, it will send a packet with FIN set to the Server and transition to FIN-WAIT-1, however it says:

In this state the client can still receive data from the server but will no longer accept data from its local application to be sent to the server.

So, my question is, what happens if the Server sends data back to the Client? since the application may probably be closed already or not in a state where it can read from the socket anymore, where is the data going to go? Also, is the client going to send ACK back for that data? what happens with the connection then? (RST maybe?)

Note: I don't care about such data, I just want to know if there is potentially a memory leak given that no process read from the TCP buffer, or if the network stack itself will take care of this.

Thank you.

2

since the application may probably be closed already or not in a state where it can read from the socket anymore, where is the data going to go?

It's implementation dependent. If the socket's closed on the application end, the TCP stack can just drop that incoming data on the floor. Alternately, you could have an implementation which didn't return from the close() call (or equivalent) until the server's FIN is received, allowing another thread to continue to read() from the socket (although a write() would receive an error). If the read() didn't complete before the server's FIN arrived, EOF could be signalled. (Replace "thread" with "callback" in an async model).

Best way to answer your question: test it on your preferred implementation(s).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.