Skip to content

Commit

Permalink
Don't close the output stream when reporting errors reading the body. (
Browse files Browse the repository at this point in the history
…#1068)

This matches the asio implementation to what the winhttp implementation was doing.

Also turned on a test that looked related; I'm not positive that this change fixed that test but it passes for me now.
  • Loading branch information
BillyONeal authored Mar 19, 2019
1 parent 3f6f844 commit 9d3b5cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
24 changes: 15 additions & 9 deletions Release/src/http/common/http_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,25 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
{
const auto& completionEvent = _get_data_available();
auto closeTask = pplx::task_from_result();

if (exceptionPtr == std::exception_ptr())
if (m_default_outstream)
{
if (m_default_outstream)
// if the outstream is one we created by default on the customer's behalf, try to close it
auto& out = outstream();
if (out.is_valid())
{
closeTask = outstream().close();
if (exceptionPtr == std::exception_ptr())
{
closeTask = out.close();
}
else
{
closeTask = out.close(exceptionPtr);
}
}
}

if (exceptionPtr == std::exception_ptr())
{
inline_continuation(closeTask, [completionEvent, body_size](pplx::task<void> t) {
try
{
Expand All @@ -459,11 +470,6 @@ void http_msg_base::_complete(utility::size64_t body_size, const std::exception_
}
else
{
if (outstream().is_valid())
{
closeTask = outstream().close(exceptionPtr);
}

inline_continuation(closeTask, [completionEvent, exceptionPtr](pplx::task<void> t) {
// If closing stream throws an exception ignore since we already have an error.
try
Expand Down
10 changes: 0 additions & 10 deletions Release/tests/functional/http/client/connections_and_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,7 @@ SUITE(connections_and_errors)
http_response rsp = client.request(msg).get();

// The response body should timeout and we should receive an exception
#ifndef _WIN32
// CodePlex 295
VERIFY_THROWS(rsp.content_ready().wait(), http_exception);
#else
VERIFY_THROWS_HTTP_ERROR_CODE(rsp.content_ready().wait(), std::errc::timed_out);
#endif
}

buf.close(std::ios_base::out).wait();
Expand Down Expand Up @@ -261,12 +256,7 @@ SUITE(connections_and_errors)

// The response body should timeout and we should receive an exception
auto readTask = rsp.body().read_to_end(streams::producer_consumer_buffer<uint8_t>());
#ifndef _WIN32
// CodePlex 295
VERIFY_THROWS(readTask.get(), http_exception);
#else
VERIFY_THROWS_HTTP_ERROR_CODE(readTask.wait(), std::errc::timed_out);
#endif
}

buf.close(std::ios_base::out).wait();
Expand Down

0 comments on commit 9d3b5cd

Please sign in to comment.