Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't close the output stream when reporting errors reading the body. #1068

Merged
merged 2 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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