Open georgebu opened 7 years ago
Seems that the http_client
cannot clean up properly if it is instantiated in global scope (and hence destructed after main()
finished).
If I run the following, it doesn't crash:
class A
{
public:
~A() { delete p; }
http_client* p;
};
int main()
{
A a;
a.p = new http_client(U("https://www.bing.com/"));
auto task =
a.p->request(web::http::methods::GET)
.then([] (pplx::task<http_response> resp) {
try {
resp.get();
std::cout << "worked" << std::endl;
} catch (...) {
std::cout << "didn't work" << std::endl;
}
});
task.wait();
return 0;
}
Also note that you should never leave tasks dangling but always call .get()
or .wait()
on them.
I had the same issue and I agree with your assessment re. global scope.
This seems to be due to global instance destruction order which is undefined across different translation units.
I had http_client
as a global in my program, and there is the shared_threadpool
which is a local static in cpprestsdk.
When destroying http_client
it accesses shared_threadpool
which was already destroyed first.
Yeah, this is an initialization order thing. I think more clear documentation is the way to go here.
code:
environment:
thread backtrace: