GeezerVison is showing github.com — Terminating with unexpected exception · Issue #358 · cpp-netlib/cpp-netlib
Terminating with unexpected exception #358DescriptionExample simple_wget crashing from time to time with error:
boost thread: trying joining itself: Resource deadlock avoided
How to reproduce
I turn off wi-fi and run command:
simple_wget https://example.com/some/archive.tar.gz
Usually command exits with code 1 and message:
Saving to: archive.tar.gz
Host not found (authoritative)
which is expected and good, but sometimes application crash in libc++ with message:
libc++abi.dylib: terminating with unexpected exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::thread_resource_error> >: boost thread: trying joining itself: Resource deadlock avoided
Process 75882 stopped
Backtrace can be found here
I can guess that exception which is thrown from join trigger std::terminate
because destructor has nothrow type (async_impl.h):
~async_client() throw ()
{
sentinel_.reset();
if (lifetime_thread_.get()) {
lifetime_thread_->join(); // BOOM!
lifetime_thread_.reset();
}
}
Some tests
- 5 crash from 1000 run
- 36 crash from 10000 run
Environment
- Mac OS X 10.9.1, boost 1.55 (debug build with libc++), openssl (system)
- iOS, boost 1.55 (debug build with libc++), openssl 1.0.1e
- I'm using
cpp-netlib-0.10.1, but cpp-netlib-0.11.0-rc3 has same behaviour
Also I've tried it on my virtual machine with Mac OS X 10.8.5 (which not using wi-fi),
there is no crashes. Activitydeanberris commented on Jan 13, 2014 So, the simple_wget example needs some love. Can you send a pull request to fix this example? I would greatly appreciate it @ruslo. ruslo commented on Jan 13, 2014 So, the simple_wget example needs some love.
I don't think that it's just example issue, I have same troubles in other situations too.
Can you send a pull request to fix this example?
The problem is that I don't know how to fix it (: Maybe it some thread management issue,
async_client ctor called in one thread and dtor called in other. Maybe it's just corrupted memory or double destruction. Simple workaround is to catch expection and ignore it, but it's more like hack... deanberris commented on Jan 23, 2014 Right, this is not a simple issue to fix. I think it's because during the lifetime of the response object, a resolution error may happen and if there's an exception thrown during the fetching of the body (or any part of the response for that matter) it would cause the destruction of the async client (if they're in the same scope). What's really happening here is a lifetime issue -- perhaps there's a way to change the destruction semantics of the async client, but I'm not entirely sure what that should be. Maybe it's just a matter of swallowing exceptions that are trying to propagate out of the destructor? ruslo commented on Jan 23, 2014
Maybe it's just a matter of swallowing exceptions that are trying to propagate out of the destructor?
I don't save logs but last time I try it (see workaround above) I've got Segmentation Fault.
FYI looks like master branch is not suffering from this issue. leecoder commented on Jun 17, 2014 I think this issue is the same with #232. (client object lifetime)
So, it will just be fixed by avoiding self join. (leecoder@af17c77)
And, it will must always be used an outside io_service.
Then, the following code works!
#include <boost/network/protocol/http/client.hpp>
int main(int argc, char** argv)
{
using namespace boost::network;
using namespace boost::network::http;
boost::asio::io_service io;
std::cout << body(client(io).get(client::request("http://boost.org/"))) << std::endl;
}deanberris commented on Jun 17, 2014 @leecoder Nice find. Can you send me a pull request on the 0.11-devel branch with that fix? added 2 commits that reference this issue on Jun 18, 2014This issue will close once commit ce53598 is merged into the 'main' branch.ce53598 This issue will close once commit 770858b is merged into the 'main' branch.770858b added 2 commits that reference this issue on Apr 14, 2015This issue will close once commit d108033 is merged into the 'master' branch.d108033 This issue will close once commit f6715f0 is merged into the 'master' branch.f6715f0 olegabr commented on Feb 13, 2018 deanberris commented on Feb 14, 2018 I think this was an oversight. Thanks for the fix!
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|