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

ui/ws: patch for perpetual browser WS reconnets #2260

Conversation

norwnd
Copy link
Contributor

@norwnd norwnd commented Mar 27, 2023

Should mitigate #2256 (comment).

Comment on lines -131 to +144
reloader()
// Once dexc is back online we have to reload book/candles (and maybe other
// stuff) otherwise we'll be missing a bunch of data for display in UI.
// Note, reloading page like this will result in ditching this WS connection
// and reestablishing new one.
reloadPage()
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are reloading app here, it seems we can just return and drop those requests being served from the queue below ? Or maybe page reload does return there anyway, just explicitly stating that's what the intent is here with return probably doesn't hurt (those queued requests might not execute before WS connection is closed due to page refresh).

Comment on lines +116 to +123
// Certain browsers have degrading performance bug when retries are issued
// perpetually (e.g. browser tab is still trying to reconnect WS to dexc after
// user shut it down but left his tab open). Refreshing page here is a patch
// for this behavior, it breaks this browser tab retry cycle.
if (retrys > 10) {
reloadPage()
return
}
Copy link
Contributor Author

@norwnd norwnd Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the exact data on this, but feel like limiting retries at 10 should provide the relief for many browsers, and it gives the user enough of time-buffer to auto-recover from temporary WS failures (beyond 10 attempts he'll have to refresh page manually).

Copy link
Member

@buck54321 buck54321 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed feelings, but I think this is fine. It is going to dump them to a browser error page if dexc is not running, where before, they would just be looking at an outdated view. Maybe this way is better.

Comment on lines +200 to 202
reloadPage () {
window.location.reload() // This triggers another websocket disconnect/connect (!)
// a fetchUser() and loadPage(window.history.state.page) might work
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have always thought that these two comments are a possible design issue that leads to the browser getting choked. It pertains to your comment at https://github.com/decred/dcrdex/pull/2260/files#r1148998740
It is strange to me that after successful websocket reconnect, it will do a full page reload, which has the effect of disconnecting the newly-established websocket connection before making a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything we'd want to change in this PR regarding that ? The way I understand current design, if page isn't refreshed we'd need at least issue loadmarket & loadcandles over this WS if we want to keep using it, and maybe page refresh helps with something else too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Investigate for possible subsequent update. Minimal time sink.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using loadPage would ensure a complete refresh of all displayed data without the added overhead of an actual page load.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, see if it works quick then. If there's any breakage or strange behavior, and it looks more nuanced, we can look at it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hang on, you're skipping the fetchUser() that the comment had instructed should precede the loadPage.

Adding await app().fetchUser() right before app().loadPage(window.history.state.page) doesn't really change anything for me (seeing same error), and it worked fine on /markets page without it too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. I guess we revert the loadPage changes since we have new bugs now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@norwnd norwnd Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still errors on /register page (when I shut down dexc and restart it, it should auto-recover) same way as above for me :(

This ^ is a minor issue on its own, but probably means there are more things potentially broken by such change.

Comment on lines +116 to +123
// Certain browsers have degrading performance bug when retries are issued
// perpetually (e.g. browser tab is still trying to reconnect WS to dexc after
// user shut it down but left his tab open). Refreshing page here is a patch
// for this behavior, it breaks this browser tab retry cycle.
if (retrys > 10) {
reloadPage()
return
}
Copy link
Member

@buck54321 buck54321 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed feelings, but I think this is fine. It is going to dump them to a browser error page if dexc is not running, where before, they would just be looking at an outdated view. Maybe this way is better.

@norwnd norwnd force-pushed the ui-ws-patch-for-perpetual-browser-ws-reconnects branch from bc6684a to c53a7ab Compare March 29, 2023 08:06
// a fetchUser() and loadPage(window.history.state.page) might work
reloadApp () {
if (window.history.state) {
app().loadPage(window.history.state.page) // recover without breaking ws connection
Copy link
Contributor Author

@norwnd norwnd Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't quite understand why this.loadPage(window.history.state.page) throws error in Console about this being undefined. Seems to be working with app(). Probably just the way JS treats this keyword.

Comment on lines 204 to 206
} else { // fall back in case history isn't available
window.location.reload() // this triggers another websocket disconnect/connect (!)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need this fallback on some pages, don't remember exactly where I saw it but window.history.state could be nil when we successfully reconnected WS.

@norwnd norwnd force-pushed the ui-ws-patch-for-perpetual-browser-ws-reconnects branch from c53a7ab to e47a6af Compare March 30, 2023 04:42
@chappjc chappjc closed this Apr 20, 2023
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

Successfully merging this pull request may close these issues.

3 participants