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

TLS client fail handler not called after second failed connection attempt on same address? #360

Closed
ghost opened this issue Jul 12, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Jul 12, 2014

zaphoyd,

I never can say thank you enough for this lib! It is simply amazing how well put together it is! The broadcast_server is all one needs to create a high performance server in minutes. When I tried deviating from it, problems were endless. When I returned to it, my development really exploded, and now I've even set up a few friends with servers. I've tried looking at every other's implementation across all languages, and they all make websocket servers almost impossible to produce. Thank you so much!

I think I might be misusing the tls client somehow. I've registered a fail handler, and it succeeds the first time; however, if I try to make subsequent connections upon the same address that previously failed, the fail handler never seems to be called again.

I've set my code to attempt connections every 3 seconds.

I'm using this context_ptr

context_ptr on_client_tls_init(websocketpp::connection_hdl hdl) {
    context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));

    try {
        ctx->set_options(boost::asio::ssl::context::default_workarounds |
                         boost::asio::ssl::context::no_sslv2 |
                         boost::asio::ssl::context::single_dh_use);
    } catch (std::exception& e) {
        std::cout << e.what() << std::endl;
    }
    return ctx;
}

I setup the connection with

client::connection_ptr con = m_client.get_connection( "wss://" + node_ip, ec );

If ec == false, I proceed with connect().

On the first failed connection, the console output is

[2014-07-12 17:08:07] [info] asio async_connect error: system:111 (Connection refused)
[2014-07-12 17:08:07] [error] handle_connect error: Underlying Transport Error
[2014-07-12 17:08:07] [info] asio async_shutdown error: asio.ssl:336462100 (uninitialized)
remote_endpoint: Transport endpoint is not connected

The fail handler fires, but upon subsequent attempts to connect to the same address, the console output is

[2014-07-12 17:08:11] [application] Close Error: invalid state
[2014-07-12 17:08:12] [application] Close Error: invalid state
[2014-07-12 17:08:13] [application] Close Error: invalid state
[2014-07-12 17:08:13] [application] Close Error: invalid state

and the fail handler doesn't fire.

Also, if no reattempt has been made then everything works as expected, but if a reattempt has been made, and a client tries to connect to a server that has tried as client to reattempt then the client that tries to connect to the reattempting server will output upon connecting:

[fatal] handle_transport_init received error: TLS handshake timed out
[disconnect] Failed: TLS handshake timed out

The client and server are both using boost::asio::io_service ios; for init_asio(&ios);.

I could not reproduce this problem with non-tls.

Please show me what I'm doing wrong.

Again, I cannot thank you enough for this amazing high performance library!

@ghost
Copy link
Author

ghost commented Jul 12, 2014

zaphoyd,

I found this thread, where you say that either the fail or open handlers are called. #263

I can confirm that neither the fail nor open threads are called, if that helps.

Thank you zaphoyd!

@ghost
Copy link
Author

ghost commented Jul 13, 2014

I also added boost::asio::ssl::context::verify_none to see if that was the cause. Same result.

@ghost
Copy link
Author

ghost commented Jul 14, 2014

It looks like trying to get the socket IP in the fail handler causes problems. Big no no.

Taking the error at its word often helps, lol.

Nothing works all that well after that point.

This issue was closed.
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

0 participants