Disconnecting in a clean fashion

45 views
Skip to first unread message

nico....@gmail.com

unread,
Aug 3, 2016, 8:03:24 AM8/3/16
to CppWAMP
Hello, 

I have yet another question. If I disconnect from the wamp server (crossbar.io version 0.13) I do:
Session->leave(wamp::Reason(), yield);
followed by:
Session->disconnect();
and still in the crossbar.io console window I see:
WampRawSocketProtocol: connection lost: reason = '[Failure instance: Traceback (failure with no frames): <class twisted.internet.error.ConnectionLost'>: Connection to the other side was lost in a non clean fashion: read error -- unknown(64).

Now I wonder if this is an issue in crossbar or if I am not properly telling cppwamp to close the session. Could somebody tell me if I did something wrong here?

Kind regards, Nico


    wamp::AsioService localIosvc;
    std::shared_ptr<wamp::Connector> tcpJson = wamp::connector<wamp::Json>(localIosvc, wamp::TcpHost("127.0.0.1", 11220));
    wamp::CoroSession<>::Ptr localSession = wamp::CoroSession<>::create(localIosvc, {tcpJson});
    try
    {
        int returnValue;
        boost::asio::spawn(localIosvc, [&](boost::asio::yield_context yield)
        {
            size_t index = localSession->connect(yield);
            wamp::SessionInfo info = localSession->join(wamp::Realm("127.0.0.1"), yield);
            wamp::Result result = localSession->call(wamp::Rpc("Set_value_to_this_integer").withArgs(42), yield);
            result.convertTo(returnValue);
            localSession->leave(wamp::Reason(), yield);
            localSession->disconnect();
        });
        localIosvc.run();
        return returnValue;
    }
    catch (const wamp::error::Failure& e)
    {
        reportError(wamp_server_error, "setIntegerValue", "Error from wamp-server: " + std::string(e.what() ) );
        return wamp_server_error;
    }


Emile Cormier

unread,
Aug 3, 2016, 11:32:32 AM8/3/16
to CppWAMP
Nico,

What you're doing appears correct. The message you see seems to have to do with the way Autobahn|Python handles peer disconnection on raw sockets. I've isolated it to this line: https://github.com/crossbario/autobahn-python/blob/10298f07f84df5ca40cec2355423ab24c46d1ca7/autobahn/twisted/rawsocket.py#L103

Autobahn uses Twisted as networking library. The reason message you see originates from this Twisted exception class: http://twistedmatrix.com/documents/8.1.0/api/twisted.internet.error.ConnectionLost.html

I also found this SO answer regarding clean disconnections on Twisted: http://stackoverflow.com/a/32440288/245265

Unclean connection shutdown is really nothing to worry about. Getting a clean exit would potentially make your shutdown process slower and buggier because it requires a bunch of additional code, and you have to be able to deal with abnormal network connection termination no matter what. In fact calling it "clean" is maybe even a bit misleading: "simultaneously confirmed" might be closer to what it's actually telling you about how the connection was closed.

From Twisted's point of view, I think a clean shutdown means that both sides are expecting the disconnection (i.e. "simultaneously confirmed"). This would be the typical scenario in an HTTP request, keeping in mind that Twisted's primary use is for implementing web servers.

With WAMP raw sockets, after a client leaves the session, the router keeps the underlying transport alive, in case the client wants to re-establish a new WAMP session on the same raw socket transport connection. If the client decides to terminate the TCP transport connection, Twisted sees it as an unexpected disconnection and considers it "non-clean".

If this message still concerns you, you should ask on the Autobahn mailing list.
Reply all
Reply to author
Forward
0 new messages