Anonymous
Anonymous

Reputation: 649

Properly terminating HTTP connection from client's side

(Original title: "Weird TCP connection close behavior")

I am troubleshooting TCP connection process using Wireshark. Client opens connection to server (I tried two different servers), and starts receiving long stream of data. At some point in time client wants to stop and sends server [FIN, ACK] packet, but server does not stop sending data, it continues till its own full stream end, and then sends its own completion packet [FIN, PSH, ACK]. I figured it out keeping reading data from the client's socket after client sent FIN packet. Also, after client sent this FIN packet, its state is FIN_WAIT, thus waiting for FIN response from server...

Why servers do not stop sending data and respond to FIN packet with acknowledgment with FIN set?

I would expect, after client sends FIN packet, server will still send several packets which were on the fly before it received FIN, but not the whole pack of long data stream!

Edit: reading this I think that web server is stuck in stage "CLOSE-WAIT: The server waits for the application process on its end to signal that it is ready to close" (third row), and its data sending process "is done" when it flushed all contents to the socket at its end, and this process can not be terminated. Weird.

Edit1: it appears my question is a little different one. I need to totally terminate connection at client's side, so that server stops sending data, and it (server) would not go crazy about forceful termination from client's side, and aborted its data sending thread at its side being ready for next connection.

Edit2: environment is HTTP servers.

Upvotes: 2

Views: 2811

Answers (2)

user207421
user207421

Reputation: 310909

The client has only shutdown the connection for output, not closed it. So the server is fully entitled to keep sending.

If the client had closed the connection, it would issue an RST in response to any further data received, which would stop the server from sending any more, modulo buffering.

Upvotes: 2

David Schwartz
David Schwartz

Reputation: 182769

Why servers do not stop sending data and respond to FIN packet with acknowledgment with FIN set?

Why should they? The client has said it won't send another request, but that doesn't mean it isn't interested in the response to any requests it has already sent.

Most protocols, such as HTTP, specify that the server should complete the response to the current request and only then close the connection. This is not an abnormal abort, it's just a promise not to send anything else.

Upvotes: 1

Related Questions