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

WebSocket client initiated heartbeating #238

Closed
ospavel opened this issue Jul 8, 2017 · 8 comments
Closed

WebSocket client initiated heartbeating #238

ospavel opened this issue Jul 8, 2017 · 8 comments

Comments

@ospavel
Copy link

ospavel commented Jul 8, 2017

Test on desktop Java 8 with Netty the code from demo (modify it a little, and use wamp.2.json instead of wamp.2.cbor):
`
mSession = new Session(mExecutor);

    // make some subscriptions
    mSession.addOnJoinListener(this::onJoinHandler);

    //
    mSession.addOnDisconnectListener((session, b) -> System.out.println("On disconnect") );

    // now create a transport list for the transport to try and which will carry our session
    List<ITransport> transports = new ArrayList<>();

    // in this case, the only transport we add is a WAMP-over-WebSocket
    // implementation on top of Netty client WebSocket
    transports.add(new NettyTransport(url));

    // now create a authenticator list for the session to announce
    // and which will authenticate our session
    List<IAuthenticator> authenticators = new ArrayList<>();

    // in this case, we don't care about authentication and so
    // the only authenticator we announce is the (pseudo) "anyonymous"
    authenticators.add(new AnonymousAuth());

    // finally, provide everything to a Client instance
    client = new Client(transports, mExecutor);

    // leave room for adding more than one sessions.
    client.add(mSession, realm, authenticators);

    CompletableFuture<ExitInfo> exitInfoCompletableFuture = client.connect();

`
When I switch off network cable there is no any reaction during infinite time. After network cable switched back - no reaction and no further work.
Thus it is not simple to know about connection problem for reconnection call.

@om26er
Copy link
Contributor

om26er commented Jul 9, 2017

Currently autobahn-java only support CBOR as serializer, implementing JSON serializer would be pretty simple but that's something we haven't looked into just yet.

Does the same issue happen with wamp.2.cbor ?

@oberstet
Copy link
Contributor

oberstet commented Jul 9, 2017

When I switch off network cable there is no any reaction during infinite time.

Without sending anything, TCP cannot distinguish between an infinitesimal slow connection and a broken connection (at least not when on different L2 network segments - try the same on a LAN). This is TCP (when used over WAN).

There are 2 things here to fix this:

  1. use a WAMP router that has WebSocket auto-pingpong/heartbeating (Crossbar.io has that)

  2. AutobahnJava needs a client initiated WebSocket auto-pingpong/hearbeating as well

  3. will allow the router to quickly detect a broken client connection and clean up resources

  4. will allow the client (your AutobahnJava based program) to quickly detect a broken router connection and clean up resources

We don't have 2. yet - but we should.

@oberstet oberstet changed the title No reaction on connection loss WebSocket client initiated heartbeating Jul 9, 2017
@oberstet oberstet added this to the Rel 17.7.1 milestone Jul 19, 2017
@oberstet
Copy link
Contributor

Again, this is very important for production use, but also in container based scenario where the order of container startup might not be fixed, and an ABJ component might be up earlier than the router, or when the router is restarted.

@om26er
Copy link
Contributor

om26er commented Jul 20, 2017

@oberstet Can you link an example on how other WAMP implementations are doing this ? Should it be a WebSocket ping frame ? what should be the timeout for it and how often shall we send the ping (how shall we expose that functionality if we want the frequency to be configurable).

Also I presume Crossbar itself does have ping-pong i.e. server initiated, is that on by default ?

@om26er
Copy link
Contributor

om26er commented Jul 20, 2017

Also, is the heartbeat interval relevant to the success of prior request ?

example: If I my heartbeat is configured to run every 10 seconds shall those 10 seconds begin after the PONG for previous PING returns or right from the time when PING was sent ?

@om26er
Copy link
Contributor

om26er commented Jul 23, 2017

First implementation attempt is available: #238

@om26er
Copy link
Contributor

om26er commented Aug 15, 2017

@oberstet this is done, closing.

@om26er om26er closed this as completed Aug 15, 2017
@pkyad
Copy link

pkyad commented May 15, 2019

By any chance is it possible to use WebSocketOptions with this to adjust the setReconnectInterval

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

No branches or pull requests

4 participants