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

Fault tolerance #413

Merged
merged 43 commits into from
May 20, 2020
Merged

Fault tolerance #413

merged 43 commits into from
May 20, 2020

Conversation

dmnisson
Copy link
Contributor

@dmnisson dmnisson commented May 9, 2020

Links

Description

  • Fault tolerance code is changed to monitor connection status in the Vuex store
  • A modal dialog is displayed if there is trouble reaching the server to begin a new session
  • Session initialization is made fault-tolerant using promise-retry
  • A warning message is displayed in the chat for a lost socket connection
  • Session data is now stored only in the Vuex store, rather than being copied in the global SessionService.currentSession

Developer self-review checklist

  • Potentially confusing code has been explained with comments
  • No warnings or errors have been introduced; all known error cases have been handled
  • Any appropriate documentation (within the code, README.md, docs, etc) has been updated
  • All edge cases have been addressed

Copy link
Contributor

@ericyliu ericyliu left a comment

Choose a reason for hiding this comment

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

left some comments! please feel free to message me on slack or respond on here if you have any questions

src/services/NetworkService.js Show resolved Hide resolved
["get", "delete", "head", "jsonp"].indexOf(method) !== -1
? http[method](url, {
timeout: FAULT_TOLERANT_HTTP_TIMEOUT
}).then(this._successHandler, this._errorHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

i would generally not handle promise returns and errors nested inside like this (as it can be difficult to follow for future programmers). instead, you could handle this promise outside like:

retryHttp: function() {
  return promiseRetry(retry => {
     ...
  }, {
    retries: FAULT_TOLERANT_HTTP_MAX_RETRIES,
    maxTimeout: FAULT_TOLERANT_HTTP_MAX_RETRY_TIMEOUT
  })
    .then(this._successHandler, this._errorHandler)
    .catch(res => {
      if (res.status === 0) { ... }
      ...
    });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The catch handler needs to be nested inside the function that is passed to promiseRetry because it needs to call the passed-in retry function to signal to promiseRetry that the function needs to be retried.

I think I'm going to use a different package for managing the retries and backoffs and rewrite this whole chunk of code--the promiseRetry module looked tempting but as I started implementing the things I needed to implement here (like stopping the requests when the user clicks "Abort") my solutions became increasingly ugly.

}
);
}
}.retryHttp();
Copy link
Contributor

Choose a reason for hiding this comment

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

are you creating the retryHttp method and then calling it immediately? unless im readying the brackets wrong, youre doing something like:

return {
   isAborted: false,
   retryHttp: function() { ... },
}.retryHttp();

so why not just directly call whatever retryHttp is doing instead of defining it and then calling it?

src/components/App/index.vue Outdated Show resolved Hide resolved
src/views/SessionView/SessionHeader.vue Outdated Show resolved Hide resolved
src/views/SessionView/index.vue Show resolved Hide resolved
src/views/SessionView/index.vue Outdated Show resolved Hide resolved
@ericyliu
Copy link
Contributor

also, if you want to, we can pair on some of this stuff as i dont know i conveyed myself super clearly and its confusing

@dmnisson dmnisson requested review from ericyliu and jkeat May 13, 2020 05:09
@dmnisson dmnisson marked this pull request as ready for review May 13, 2020 05:09
ericyliu
ericyliu previously approved these changes May 18, 2020
Copy link
Contributor

@ericyliu ericyliu left a comment

Choose a reason for hiding this comment

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

looks great! thanks for the changes

this.joinSession(this.session._id);
} else {
location.reload();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

a way to avoid the crazy if statement could be:

if (this.session && this.session._id) {
  if (this.session.student && this.session.student._id === this.user._id) return location.reload();
  if (this.session.volunteer && this.session.volunteer._id === this.user.Id) return location.reload();
  return this.joinSession(this.session._id);
}

i think this looks more readable, but up to you whether you want to change or not

@@ -174,9 +172,6 @@ export default {
},
sockets: {
"session-change"(sessionData) {
SessionService.currentSession.sessionId = sessionData._id;
SessionService.currentSession.data = sessionData;
Copy link
Member

Choose a reason for hiding this comment

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

awesome to get rid of this :)

package.json Show resolved Hide resolved
@jkeat jkeat mentioned this pull request May 19, 2020
4 tasks
@jkeat jkeat self-requested a review May 19, 2020 20:53
# Conflicts:
#	src/views/SessionView/index.vue
@jkeat jkeat self-requested a review May 20, 2020 17:10
Copy link
Member

@jkeat jkeat left a comment

Choose a reason for hiding this comment

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

great work @dmnisson!

@jkeat jkeat merged commit db4026d into master May 20, 2020
@jkeat jkeat deleted the show-connection-warning branch May 20, 2020 17:11
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