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

Request resources asynchronously when the socket connection fails #1482

Merged
merged 2 commits into from
Jan 28, 2020

Conversation

andresmgot
Copy link
Contributor

Description of the change

This PR creates an onError handler that can be called if the socket connection throws an error. This triggers an interval to re-request resources every 5s. This interval can be closed the same way than the socket calling closeTimer.

I have tested this removing the Nginx configuration that allows the socket connection, in the GIF below, you can see how the application gets updated even without the socket. When leaving the view, the timer gets cleared so we don't re-request more those resources.

final_5e2b0e93faec2c0016803a64_5

Applicable issues

Copy link
Contributor

@absoludity absoludity left a comment

Choose a reason for hiding this comment

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

That's a great fallback Andres!

dispatch(receiveResource({ key, resource }));
},
{
onErrorHandler: () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we only be doing this for a specific error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are several reasons why the socket may fail: a network error, a forbidden error if the user doesn't have permissions to "watch" a resource, a timeout after sometime... In all of those cases it's fine to jump to the fallback IMO, that's why I am not filtering the error. Are you thinking on a specific case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I was just wondering if it was intentional that it was a catch all (ie. always drop to the fallback).

dispatch(requestResource(key));
// If it's not the first request, we can skip the request REDUX event
// to avoid the loading animation
if (shouldDispatchRequest !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not if (shouldDispatchRequest) { ? Ah, perhaps existing call-sites haven't been updated so get a default of undefined which isn't true? Not sure, but wonder if polling would be a better arg, which is fine defaulting to false/undefined, so here can be if(!polling) {...}. Anyway, fine either way, just found shouldDispatchRequest a little confusing at first because it implies it's talking about whether the actual request (to the server) will be dispatched, but it's not, it's just the redux state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not if (shouldDispatchRequest) { ? Ah, perhaps existing call-sites haven't been updated so get a default of undefined which isn't true?

yes, it's because of that

Not sure, but wonder if polling would be a better arg, which is fine defaulting to false/undefined, so here can be if(!polling) {...}. Anyway, fine either way, just found shouldDispatchRequest a little confusing at first because it implies it's talking about whether the actual request (to the server) will be dispatched, but it's not, it's just the redux state.

I think I don't understand what polling would mean in this context? I am okay changing the var name though.

Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't so much about changing the name as opposed to choosing something such that the default value could be undefined/false, so that you could just do if (!polling) {...} (and perhaps be a little clearer). But totally fine as is, imo.

@andresmgot andresmgot merged commit 0ff31ec into master Jan 28, 2020
@andresmgot andresmgot deleted the socketAlternative branch January 29, 2020 13:36
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.

Web Socket connections don't upgrade on GKE
2 participants