cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Try to resend request if connection has been closed.

Open blacktea opened this issue 3 years ago • 2 comments

Hi, all!

Case: We've got a client that sends messages to a server. I came across a problem when client failed to write request body. I found out that the reason was the connection was closed after the "keep-alive" timeout expired. They use HTTP/1.1 and Keep-Alive connection.

Tcpdump trace: image

155 - client, 159 - server. At the beginning, the client sends a request and accepts a response from the server. Then, in 19 secs FIN packet is arrived. At 209.852367 we try to write headers. In response, we accepts RST packet. In cpprestsdk it means "Broken pipe" at https://github.com/microsoft/cpprestsdk/blob/master/Release/src/http/client/http_client_asio.cpp#L1303.

My solution: There is an attempt to restore the closed connection at https://github.com/microsoft/cpprestsdk/blob/master/Release/src/http/client/http_client_asio.cpp#L1347. I decided to use this method to handle body write error. I managed to reproduce the error in unit-tests.

blacktea avatar Feb 08 '22 10:02 blacktea

CLA assistant check
All CLA requirements met.

@barcharcraz, Could you review please?

blacktea avatar Apr 11 '22 06:04 blacktea