This repository has been archived by the owner on Sep 4, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #86: simple_http: fix detecting broken pipe on request
0de1c58 simple_http: unit test to demonstrate detecting broken pipe (Philip Robinson) 0cab08a simple_http: add second send attempt if read indicates socket is broken (Philip Robinson) Pull request description: While upgrading from v0.11 to v0.14 I noticed that I started getting the following error when the server had disconnected the socket between requests, in our case due to the server idle timeout: ``` Err(Transport(HttpResponseTooShort { actual: 0, needed: 12 })) ``` The same issue as is reported in #79 I believe. I noticed #84 was an attempt to solve the problem and I think I found out why it didn't work as expected. The client is using a `BufWriter` to write the `TcpStream` and unless you flush the buffer you will not see the broken pipe error in time in order to request a fresh connection. This PR adds in the flushes and provides a unit test demonstrating that it fixes the issue. If you comment out the flushes you will see the symptom reported in #79. ## Revision The first approach of flushing the write buffer twice during the POST angered HTTP servers that expected the request to be contained in a single message. The revised approach uses the method that is advocated in the unix docs to detect a broken TCP stream which is that if the blocking `read` operation returns 0 bytes then the socket is closed. So this PR creates a buffer to hold the request, attempts to send it and then reads the response. If the response was length 0 it will attempt to get a fresh socket and send the request a second time. ACKs for top commit: apoelstra: ACK 0de1c58 Tree-SHA512: 0871a0c57b3d63b2d7b0ebd4bb1bb2f4f68bb88b7fe55fa8f3566f49fbd3aa33920e7e953e50320797bf2b1791ea223e6ef40f57901fbc3908a005e3ea167f77
- Loading branch information