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

Client crashes if stopped during handhake with ASIO_STANDALONE #673

Open
tjahn opened this issue Oct 8, 2017 · 0 comments
Open

Client crashes if stopped during handhake with ASIO_STANDALONE #673

tjahn opened this issue Oct 8, 2017 · 0 comments

Comments

@tjahn
Copy link

tjahn commented Oct 8, 2017

Hello,

I experience a bug when using ASIO_STANDALONE.
When the endpoint is stopped during an active handshake I get the following error in the destructor of the endpoint:

malloc: *** error for object 0x7fea5c0005d0: pointer being freed was not allocated

It seems as if asio deletes the object during the call of stop() and tries to delete it again in the destructor. boost::asio 1.65.1 does not show this behaviour.

I really would prefer using the header-only standalone asio version, since I try to keep my dependencies small for my cross-plattform application. The problem arises when I tried to shut down my endpoint. After a specific time I can not wait any longer and have to stop the endpoint.

I am using the latest version of asio from https://github.com/chriskohlhoff/asio on MacOS Sierra.
To replicate the bug compile this example with ASIO_STANDALONE defined:

#include <chrono>
#include <thread>
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>

#ifndef ASIO_STANDALONE 
namespace asio { using namespace boost::asio; }
#endif

using namespace std;

using WsClient  = websocketpp::client<websocketpp::config::asio_tls_client>;
using WsMessage = websocketpp::config::asio_tls_client::message_type   ;
using WsContext = shared_ptr<asio::ssl::context>     ;

int main(){
  WsClient client;

  client.init_asio();
  auto sslContext = make_shared<asio::ssl::context>( asio::ssl::context::sslv23 );
  client.set_tls_init_handler( [sslContext]( auto hdl ){ return sslContext; });

  websocketpp::lib::error_code ec;
  auto con = client.get_connection( "wss://google.de:8080", ec ); // some uri to wait for
  if( ec ) throw runtime_error("can not create connection: "+ec.message() );

  client.connect(con);
  auto trd = thread( [&](){ client.run();  });

  this_thread::sleep_for(.5s); // wait for the handshake to start
  client.stop();               // stop before timeout kicks in

  trd.join();
  return 0;
}

Any help would be greatly appreciated

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

No branches or pull requests

1 participant