Prevent transport adapter to keep pulling for data on a closed connection (#780)

* thow if connection is closed when reading response

* improve comment

* format
This commit is contained in:
Victor Vazquez 2020-10-14 19:18:43 -07:00 committed by GitHub
parent 724e6ca512
commit d4ff61919f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -525,6 +525,12 @@ void CurlSession::ReadStatusLineAndHeadersFromRawResponse(
// Try to fill internal buffer from socket.
// If response is smaller than buffer, we will get back the size of the response
bufferSize = ReadFromSocket(context, this->m_readBuffer, Details::c_DefaultLibcurlReaderSize);
if (bufferSize == 0)
{
// closed connection, prevent application from keep trying to pull more bytes from the wire
throw TransportException(
"Connection was closed by the server while trying to read a response");
}
// returns the number of bytes parsed up to the body Start
bytesParsed = parser.Parse(this->m_readBuffer, static_cast<size_t>(bufferSize));
}