You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 1, 2026. It is now read-only.
Unhandled std::logic_error exception after resending HTTP 'PUT' requests on Linux #1301
We have C++ REST client application that uses cpprestsdk. We have the scenario when we get unhandled std::logic_error exception (uninitialized stream object).
The mentioned scenario is:
client sends to the server PUT request with the meaningful body
server replies with UNAUTHORIZED error if the request's access token is expired
client handles this error, requests the new access token using another HTTP requests
client tries to resend the former PUT request with updated access token (Authorization header)
cpprestsdk code throws std::logic_error exception
I managed to debug the case under Windows. I see that after the first attempt to send the request we have empty body (empty 'm_inStream: concurrency::streams::istream' field).
The stream is reset here: void request_context::complete_headers()
{
// We have already read (and transmitted) the request body. Should we explicitly close the stream?
// Well, there are test cases that assumes that the istream is valid when t receives the response!
// For now, we will drop our reference which will close the stream if the user doesn't have one.
m_request.set_body(Concurrency::streams::istream());
m_request_completion.set(m_response);
}
The main question is whether we actually have to reset the body after request has been send? I will try to comment the string with the body clearing and see the result.
Environment:
Client side - cpprestsdk 2.10.14 (actually the latest sources) Linux static build with gcc4.8, boost 1.68.0 Linux static build with gcc4.8.
Server side - .NET Core REST server.
Stack trace for the unhandled exception:
#0 0x000000000041d420 in std::logic_error::logic_error(std::string const&)PLT (@plt) () #1 0x00000000005e906c in Concurrency::streams::basic_istream::helper (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/include/cpprest/streams.h:1093 #2 Concurrency::streams::basic_istream::streambuf (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/include/cpprest/streams.h:1040 #3 web::http::client::details::request_context::_get_readbuffer (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client.cpp:146 #4 0x00000000006a5a73 in web::http::client::details::asio_context::handle_write_large_body (this=this@entry=0x7fffc0012058, ec=...) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client_asio.cpp:1259 #5 0x00000000006a5c36 in web::http::client::details::asio_context::handle_write_headers (this=0x7fffc0012058, ec=...) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client_asio.cpp:1165 #6 0x000000000069fc7b in boost::_mfi::mf1<void, web::http::client::details::asio_context, boost::system::error_code const&>::operator()<std::shared_ptrweb::http::client::details::asio_context > (a1=...,
u=std::shared_ptr (count 2, weak 3) 0x7fffc0012058, this=0x7fffecb2dd60) at /srv/build/agent/work/21711c7319e2844b/boost.lin.gcc48.rt-static.x86_64.1.68.0.3/include/boost/bind/mem_fn_template.hpp:171 #7 boost::_bi::list2<boost::_bi::value<std::shared_ptrweb::http::client::details::asio_context >, boost::arg<1> (*)()>::operator()<boost::_mfi::mf1<void, web::http::client::details::asio_context, const boost::system::error_code&>, boost::_bi::rrlist2<const boost::system::error_code&, long unsigned int const&> > (a=, f=..., this=0x7fffecb2dd70)
at /srv/build/agent/work/21711c7319e2844b/boost.lin.gcc48.rt-static.x86_64.1.68.0.3/include/boost/bind/bind.hpp:319
...
Stack trace for clearing the body after the first attempt (running on Windows):
slimprinter_service.exe!std::swap<Concurrency::streams::details::basic_istream_helper * __ptr64,void>(Concurrency::streams::details::basic_istream_helper * & _Left=0x000002133aa5cb70, Concurrency::streams::details::basic_istream_helper * & _Right=0x0000000000000000) Line 52 C++
slimprinter_service.exe!std::_Ptr_base<Concurrency::streams::details::basic_istream_helper >::_Swap(std::_Ptr_base<Concurrency::streams::details::basic_istream_helper > & _Right={...}) Line 312 C++
slimprinter_service.exe!std::shared_ptr<Concurrency::streams::details::basic_istream_helper >::swap(std::shared_ptr<Concurrency::streams::details::basic_istream_helper > & _Other={...}) Line 621 C++
slimprinter_service.exe!std::shared_ptr<Concurrency::streams::details::basic_istream_helper >::operator=(const std::shared_ptr<Concurrency::streams::details::basic_istream_helper > & _Right={...}) Line 572 C++
slimprinter_service.exe!Concurrency::streams::basic_istream::operator=(const Concurrency::streams::basic_istream & other={...}) Line 613 C++
slimprinter_service.exe!web::http::details::http_msg_base::set_instream(const Concurrency::streams::basic_istream & instream={...}) Line 347 C++
slimprinter_service.exe!web::http::details::http_msg_base::set_body(const Concurrency::streams::basic_istream & instream={...}, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & contentType={...}) Line 1106 C++
slimprinter_service.exe!web::http::http_request::set_body(const Concurrency::streams::basic_istream & stream={...}, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & content_type={...}) Line 1220 C++
slimprinter_service.exe!web::http::client::details::request_context::complete_headers() Line 54 C++
slimprinter_service.exe!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle=0x000002133aaa3500, unsigned __int64 context=2281611315296, unsigned long statusCode=131072, void * statusInfo=0x0000000000000000, unsigned long statusInfoLength=0) Line 2085 C++
We are currently using the solution that I have described above.
src/http/client/http_client.cpp: void request_context::complete_headers()
We stopped request's body resetting by removing the line m_request.set_body(Concurrency::streams::istream());
Activity
oleevg commentedon Dec 27, 2019
Environment:
Client side - cpprestsdk 2.10.14 (actually the latest sources) Linux static build with gcc4.8, boost 1.68.0 Linux static build with gcc4.8.
Server side - .NET Core REST server.
Stack trace for the unhandled exception:
#0 0x000000000041d420 in std::logic_error::logic_error(std::string const&)PLT (@plt) ()
#1 0x00000000005e906c in Concurrency::streams::basic_istream::helper (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/include/cpprest/streams.h:1093
#2 Concurrency::streams::basic_istream::streambuf (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/include/cpprest/streams.h:1040
#3 web::http::client::details::request_context::_get_readbuffer (this=) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client.cpp:146
#4 0x00000000006a5a73 in web::http::client::details::asio_context::handle_write_large_body (this=this@entry=0x7fffc0012058, ec=...) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client_asio.cpp:1259
#5 0x00000000006a5c36 in web::http::client::details::asio_context::handle_write_headers (this=0x7fffc0012058, ec=...) at /srv/build/agent/work/21711c7319e2844b/cpprestsdk/cpprest/src/http/client/http_client_asio.cpp:1165
#6 0x000000000069fc7b in boost::_mfi::mf1<void, web::http::client::details::asio_context, boost::system::error_code const&>::operator()<std::shared_ptrweb::http::client::details::asio_context > (a1=...,
u=std::shared_ptr (count 2, weak 3) 0x7fffc0012058, this=0x7fffecb2dd60) at /srv/build/agent/work/21711c7319e2844b/boost.lin.gcc48.rt-static.x86_64.1.68.0.3/include/boost/bind/mem_fn_template.hpp:171
#7 boost::_bi::list2<boost::_bi::value<std::shared_ptrweb::http::client::details::asio_context >, boost::arg<1> (*)()>::operator()<boost::_mfi::mf1<void, web::http::client::details::asio_context, const boost::system::error_code&>, boost::_bi::rrlist2<const boost::system::error_code&, long unsigned int const&> > (a=, f=..., this=0x7fffecb2dd70)
at /srv/build/agent/work/21711c7319e2844b/boost.lin.gcc48.rt-static.x86_64.1.68.0.3/include/boost/bind/bind.hpp:319
...
Stack trace for clearing the body after the first attempt (running on Windows):
slimprinter_service.exe!std::swap<Concurrency::streams::details::basic_istream_helper * __ptr64,void>(Concurrency::streams::details::basic_istream_helper * & _Left=0x000002133aa5cb70, Concurrency::streams::details::basic_istream_helper * & _Right=0x0000000000000000) Line 52 C++
slimprinter_service.exe!std::_Ptr_base<Concurrency::streams::details::basic_istream_helper >::_Swap(std::_Ptr_base<Concurrency::streams::details::basic_istream_helper > & _Right={...}) Line 312 C++
slimprinter_service.exe!std::shared_ptr<Concurrency::streams::details::basic_istream_helper >::swap(std::shared_ptr<Concurrency::streams::details::basic_istream_helper > & _Other={...}) Line 621 C++
slimprinter_service.exe!std::shared_ptr<Concurrency::streams::details::basic_istream_helper >::operator=(const std::shared_ptr<Concurrency::streams::details::basic_istream_helper > & _Right={...}) Line 572 C++
slimprinter_service.exe!Concurrency::streams::basic_istream::operator=(const Concurrency::streams::basic_istream & other={...}) Line 613 C++
slimprinter_service.exe!web::http::details::http_msg_base::set_instream(const Concurrency::streams::basic_istream & instream={...}) Line 347 C++
slimprinter_service.exe!web::http::details::http_msg_base::set_body(const Concurrency::streams::basic_istream & instream={...}, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & contentType={...}) Line 1106 C++
slimprinter_service.exe!web::http::http_request::set_body(const Concurrency::streams::basic_istream & stream={...}, const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > & content_type={...}) Line 1220 C++
slimprinter_service.exe!web::http::client::details::request_context::complete_headers() Line 54 C++
slimprinter_service.exe!web::http::client::details::winhttp_client::completion_callback(void * hRequestHandle=0x000002133aaa3500, unsigned __int64 context=2281611315296, unsigned long statusCode=131072, void * statusInfo=0x0000000000000000, unsigned long statusInfoLength=0) Line 2085 C++
ALGdev commentedon Mar 2, 2020
Hi, Im trying to archieve something similar but using HTTP interceptors.
Did you manage to solve this problem?
Thank you.
oleevg commentedon Mar 2, 2020
Hi.
We are currently using the solution that I have described above.
src/http/client/http_client.cpp: void request_context::complete_headers()
We stopped request's body resetting by removing the line
m_request.set_body(Concurrency::streams::istream());And everything is working fine so far.