The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
7.96k
stars
1.65k
forks
source link
Try to resend request if connection has been closed. #1682
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.
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](https://user-images.githubusercontent.com/42189825/152962404-6736fbbd-8ceb-43ea-b243-7625f117bfe2.png)
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.