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

Turn off background updates after failures and reduce logging #1379

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/components/mixins/UtilityMixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import Component from 'vue-class-component';
import R2Error from '../../model/errors/R2Error';
import CdnProvider from '../../providers/generic/connection/CdnProvider';
import ConnectionProvider from '../../providers/generic/connection/ConnectionProvider';
import { isCanceledByRequest, isNetworkError } from '../../utils/HttpUtils';

@Component
export default class UtilityMixin extends Vue {
readonly REFRESH_INTERVAL = 5 * 60 * 1000;
private tsRefreshFailed = false;
private tsRefreshInterval: NodeJS.Timeout|undefined;

hookThunderstoreModListRefresh() {
setInterval(this.tryRefreshThunderstoreModList, this.REFRESH_INTERVAL);
this.tsRefreshInterval = setInterval(
this.tryRefreshThunderstoreModList,
this.REFRESH_INTERVAL
);
}

async refreshThunderstoreModList() {
Expand Down Expand Up @@ -48,8 +53,26 @@ export default class UtilityMixin extends Vue {
await this.refreshThunderstoreModList();
} catch (e) {
if (this.tsRefreshFailed) {
console.error("Two consecutive background refresh attempts failed");
throw e;
// Turn off the background update process after two consecutive
// attempts have failed, as assumably further retries would just
// drain resources and possibly cause other issues with little
// hope of succeeding.
clearInterval(this.tsRefreshInterval);
this.tsRefreshInterval = undefined;

this.$store.commit("error/handleError", new R2Error(
"Background updates halted",
`Two consecutive attempts to update the online mod list on the
background have failed, and the background update has been
disabled. You can continue to use the app, but the online mod
list won't be updated automatically anymore. Error code: "${e}"`,
"Restart the app to reactivate the background update."
));

// Rethrow non-trivial errors to get them logged.
if (!isCanceledByRequest(e) && !isNetworkError(e)) {
throw e;
}
}

this.tsRefreshFailed = true;
Expand Down
6 changes: 6 additions & 0 deletions src/utils/HttpUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export const makeLongRunningGetRequest = async (
export const isNetworkError = (responseOrError: unknown) =>
responseOrError instanceof Error && responseOrError.message === "Network Error";

/**
* Is the request canceled by the AbortController like the one used by makeLongRunningGetRequest?
*/
export const isCanceledByRequest = (responseOrError: unknown) =>
axios.isCancel(responseOrError);

/**
* Is the Error thrown by Axios request caused by a response timeout?
*/
Expand Down
Loading