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)); }