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

[MM-53295] Fix crash in diagnostics when server is unreachable #2771

Merged
merged 2 commits into from
Jun 26, 2023

Conversation

devinbinnie
Copy link
Member

Summary

When running diagnostics, we check the current configured servers to ensure reachability. Unfortunately, there was a bug introduced when refactoring for the ServerManager in which the wrong URL was provided and would always crash. This revealed a further bug where if the server was unreachable, diagnostics would always crash.

This PR fixes the issue with the wrong URL, as well as catches the potential crash that could happen.

Ticket Link

https://mattermost.atlassian.net/browse/MM-53295
Closes #2769

Fix crash in diagnostics when server is unreachable

@devinbinnie devinbinnie added the 2: Dev Review Requires review by a core committer label Jun 22, 2023
@devinbinnie devinbinnie added this to the v5.5.0 milestone Jun 22, 2023
@@ -24,7 +25,7 @@ const run = async (logger: ElectronLog): Promise<DiagnosticStepResponse> => {
throw new Error(`Invalid server configuration. Server Url: ${server.url}, server name: ${server.name}`);
}

const serverOnline = await isOnline(logger, `${server.url}/api/v4/system/ping`);
const serverOnline = await isOnline(logger, parseURL(`${server.url}/api/v4/system/ping`)?.toString());
Copy link
Member

Choose a reason for hiding this comment

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

If the parseUrl here returns undefined, will it get defaulted above in the isOnline function? Do we need to check for undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not in this case no, it's very unlikely that this is undefined but if it ever is (would only happen if someone tried to break something) the default case would catch it from crashing.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar what this is trying to do just want to make sure that is OK to default to `'https://community.mattermost.com/api/v4/system/ping' in the rare case it's an invalid url here

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that's fine, this is all part of a health check in case users experience issues. Worst case scenario it pings community, which is only an indication that their server URL is wrong/unavailable. It's actually potentially helpful for it to work this way :P

Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand the difference here, the use of parseURL here is only to validate if its a current URL, right? If so, are we including all the basic stuff such as removing trailing slashes, whitespaces, missing protocols, etc?

Copy link
Member Author

Choose a reason for hiding this comment

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

parseURL is here to remove extra slashes, since we assume that one is needed before the api route. But often the slash is already there so we run it through parseURL to make sure it's all correct.

The whitespace and missing protocols should already all be taken care of at this point before the server was even added.

@@ -24,7 +25,7 @@ const run = async (logger: ElectronLog): Promise<DiagnosticStepResponse> => {
throw new Error(`Invalid server configuration. Server Url: ${server.url}, server name: ${server.name}`);
}

const serverOnline = await isOnline(logger, `${server.url}/api/v4/system/ping`);
const serverOnline = await isOnline(logger, parseURL(`${server.url}/api/v4/system/ping`)?.toString());
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar what this is trying to do just want to make sure that is OK to default to `'https://community.mattermost.com/api/v4/system/ping' in the rare case it's an invalid url here

@@ -24,7 +25,7 @@ const run = async (logger: ElectronLog): Promise<DiagnosticStepResponse> => {
throw new Error(`Invalid server configuration. Server Url: ${server.url}, server name: ${server.name}`);
}

const serverOnline = await isOnline(logger, `${server.url}/api/v4/system/ping`);
const serverOnline = await isOnline(logger, parseURL(`${server.url}/api/v4/system/ping`)?.toString());
Copy link
Member

Choose a reason for hiding this comment

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

Trying to understand the difference here, the use of parseURL here is only to validate if its a current URL, right? If so, are we including all the basic stuff such as removing trailing slashes, whitespaces, missing protocols, etc?

@devinbinnie devinbinnie merged commit 8505733 into mattermost:master Jun 26, 2023
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core committer release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Crash]: When running "Run Diagnostics" from the help menu, the app crashes
4 participants