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

boost::exception_detail::clone_impl thrown with 0.13-release #776

Open
biot023 opened this issue Aug 17, 2017 · 4 comments · May be fixed by #841
Open

boost::exception_detail::clone_impl thrown with 0.13-release #776

biot023 opened this issue Aug 17, 2017 · 4 comments · May be fixed by #841

Comments

@biot023
Copy link

biot023 commented Aug 17, 2017

Hi -- I'm getting this error thrown:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<std::__exception_ptr::exception_ptr>'

A quick google of the error turned this stack overflow question up.

At the end of that ticket is this comment:

The author of library found the solution to be using the same instance of the client and not creating/destroying it each time

If I assume that the same approach would work for me, I have the issue that my cpp-netlib client is being created in a fire-and-forget thread each time it is needed. This is because I need them to run concurrently.

Would I need to implement a pool of clients to handle this? Has anyone seen anything similar that they could point me to, if I should?

Thanks for any and all assistance,
Doug.

@deanberris
Copy link
Member

Instances of the client are thread-safe. You can reuse the object in multiple threads without explicit synchronisation.

@biot023
Copy link
Author

biot023 commented Aug 18, 2017

Ah, then I was definitely barking up the wrong tree -- thanks for letting me know, I'll come at the problem another way.
Thanks again,
Doug.

@Plaristote
Copy link

Plaristote commented Aug 29, 2017

I used to work with a version of cpp-netlib that I compiled around 6 months ago, and I was able to communicate with Google's API without any issues... when I recompiled everything from scratch around a month ago, this problem appeared.

I've written some code to consistently reproduce the issue. The following program allows you to make a single http query and outputs the response:

// main.cpp
#define BOOST_NETWORK_ENABLE_HTTPS
#include <boost/program_options.hpp>
#include <boost/network/protocol/http.hpp>
#include <string>
#include <utility>
#include <iostream>

int main(int argc, char* argv[]) {
  using namespace boost::network;

  boost::program_options::variables_map options;
  {
    using namespace boost::program_options;

    options_description options_d("Options");
    options_d.add_options()
      ("headers", value<bool>(), "print headers")
      ("status",  value<bool>(), "print status and message")
      ("source",  value<std::string>(), "source URL")
      ;

    store(parse_command_line(argc, argv, options_d), options);
    notify(options);
  }

  if (options.count("source") < 1) {
    std::cout << "Error: Source URL required." << std::endl;
    return EXIT_FAILURE;
  }

  std::string source = options["source"].as<std::string>();
  bool show_headers = options.count("headers") ? true : false;
  bool show_status = options.count("status") ? true : false;

  http::client::request request(source);
  http::client::string_type destination_ = host(request);

  request << ::boost::network::header("Connection", "close");
  http::client::options client_options;
  client_options.follow_redirects(true);
  http::client client(client_options);
  http::client::response response = client.get(request);

  if (show_status)
    std::cout << status(response) << " " << status_message(response)
              << std::endl;

  if (show_headers) {
    auto headers_ = response.headers();
    for (auto const& header : headers_) {
      std::cout << header.first << ": " << header.second << std::endl;
    }
    std::cout << std::endl;
  }

  std::cout << body(response);
  return EXIT_SUCCESS;
}
# Makefile
CPPNETLIB_PATH=/usr/local/lib64

all:
        g++ main.cpp \
        -lssl \
        -lcrypto \
        -lboost_program_options \
        -lpthread \
        -lboost_system \
        -lboost_thread \
        ${CPPNETLIB_PATH}/libcppnetlib-uri.a \
        ${CPPNETLIB_PATH}/libcppnetlib-client-connections.a

Running the program with the following URL will consistently crash, producing this output:

$> ./a.out --source "https://accounts.google.com/o/oauth2/auth"
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<std::__exception_ptr::exception_ptr>'
[1]    32389 abort (core dumped)  ./a.out --source "https://accounts.google.com/o/oauth2/auth"

The exception is thrown when calling boost::network::http::body(response).

Note that calling GET https://accounts.google.com/o/oauth2/auth will answer with 400 Bad request. But this isn't what causes the problem: I have verified that even when building a proper query that gets a 200 answer, trying to retrieve the body will throw this exception.

@kealennieh
Copy link

Any solutions ? I've got the same problem in the latest version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants