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

onOpen callback not invoked after Websocket connection fails and is restored #1121

Closed
jdahlstrom opened this issue Jun 4, 2013 · 6 comments
Labels

Comments

@jdahlstrom
Copy link

If a Websocket connection fails (eg. due to a temporary network failure), onClose() is called on the client side and the client tries to open a new connection.

When a reconnect attempt is made, onReconnect() is called. If the network is still down, the reconnection immediately fails and onClose() is again called by the websocket onclose handler. However, if the network is back up, the reconnection succeeds but the user then gets no notification that the connection was established (no onOpen() called) and it's again possible to push(). (If push() is called while the connection is down, it is a no-op due to _websocket being null.)

This is problematic, as even though we can notify the end user and disable the UI when the connection is lost, it's not possible to reliably know when the connection is restored and let the user to continue using the application. Neither can we queue a request and send it once we're back online. Another problem is that the original onClose() call doesn't provide any information that this was an unexpected close.

Thanks for any help,

Johannes

@jdahlstrom
Copy link
Author

Actually, onClose does not seem to be called when a reconnection attempt fails. callback is called, though, with response state closed.

@jfarcand
Copy link
Member

jfarcand commented Jun 4, 2013

@jdahlstrom Which version of Atmosphere are you using? Can you try with 1.0.13? For sure if you can use 1.1.0.RC3 there is an improved set of callback (like onReopen()) that will help. See this sample for an example. In 1.0.14, atmosphere.js will also be available so a backport is possible.

@jdahlstrom
Copy link
Author

Oh, sorry. I'm at Vaadin; we're using 1.0.13 and really wouldn't like to depend on a prerelease version.

I wonder if we could just patch _executeWebSocket in our bundled jquery.atmosphere.js to always invoke _open() in _websocket.onopen() regardless of the value of webSocketOpened? I tried this and it seems to work the way we want but there may be unwanted side effects.

@jfarcand
Copy link
Member

jfarcand commented Jun 5, 2013

@jdahlstrom that will work, but onOpen will be opened called many times instead of just one. But if you handle the logic in your application, go for it.

@jdahlstrom
Copy link
Author

Okay, thanks! We need to do our own state bookkeeping anyway so that's not a problem.

@jfarcand
Copy link
Member

This is now fixed, onReopen will be called once the reconnection occurs. Thanks!

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

No branches or pull requests

2 participants