loudapet / 42webserv

This project is about writing one's own HTTP server
2 stars 0 forks source link

Review TCP close connection problem #26

Closed loudapet closed 3 months ago

loudapet commented 3 months ago

As per RFC9112:

If a server performs an immediate close of a TCP connection, there is a significant risk that the client will not be able to read the last HTTP response. If the server receives additional data from the client on a fully closed connection, such as another request sent by the client before receiving the server's response, the server's TCP stack will send a reset packet to the client; unfortunately, the reset packet might erase the client's unacknowledged input buffers before they can be read and interpreted by the client's HTTP parser.

To avoid the TCP reset problem, servers typically close a connection in stages. First, the server performs a half-close by closing only the write side of the read/write connection. The server then continues to read from the connection until it receives a corresponding close by the client, or until the server is reasonably certain that its own TCP stack has received the client's acknowledgement of the packet(s) containing the server's last response. Finally, the server fully closes the connection.

Not sure how we're handling connection close at the moment, but this should be handled elegantly if possible.

andreaulicna commented 3 months ago

Subject doesn't allow shutdown that is needed to solve this.