From d4ff61919f4805228a5ca81ed849184bbc8fa556 Mon Sep 17 00:00:00 2001 From: Victor Vazquez Date: Wed, 14 Oct 2020 19:18:43 -0700 Subject: [PATCH] Prevent transport adapter to keep pulling for data on a closed connection (#780) * thow if connection is closed when reading response * improve comment * format --- sdk/core/azure-core/src/http/curl/curl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sdk/core/azure-core/src/http/curl/curl.cpp b/sdk/core/azure-core/src/http/curl/curl.cpp index fd4c6361a..db4521bfb 100644 --- a/sdk/core/azure-core/src/http/curl/curl.cpp +++ b/sdk/core/azure-core/src/http/curl/curl.cpp @@ -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(bufferSize)); }