Skip to content

Commit f5e5ad9

Browse files
authored
Merge pull request element-hq#9960 from vector-im/travis/fail-fast-but-not-too-fast
Do not fail on server liveliness checks during startup
2 parents 8ec1c1c + 490595c commit f5e5ad9

4 files changed

Lines changed: 50 additions & 19 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ For a good example, see https://riot.im/develop/config.json.
113113
Riot to use. The object is the same as returned by [https://<server_name>/.well-known/matrix/client](https://matrix.org/docs/spec/client_server/latest.html#get-well-known-matrix-client),
114114
with added support for a `server_name` under the `m.homeserver` section to display
115115
a custom homeserver name. Alternatively, the config can contain a `default_server_name`
116-
instead which is where Riot will go to get that same object - see the `.well-known`
117-
link above for more information. Note that the `default_server_name` is used to get
118-
a complete server configuration whereas the `server_name` in the `default_server_config`
119-
is for display purposes only.
116+
instead which is where Riot will go to get that same object, although this option is
117+
deprecated - see the `.well-known` link above for more information on using this option.
118+
Note that the `default_server_name` is used to get a complete server configuration
119+
whereas the `server_name` in the `default_server_config` is for display purposes only.
120120
* *Note*: The URLs can also be individually specified as `default_hs_url` and
121121
`default_is_url`, however these are deprecated. They are maintained for backwards
122122
compatibility with older configurations. `default_is_url` is respected only

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Unexpected error preparing the app. See console for details.": "Unexpected error preparing the app. See console for details.",
3-
"This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below": "This installation of Riot seems to have an invalid server configuration. If you are the administrator, please correct the error below",
3+
"Your Riot is misconfigured": "Your Riot is misconfigured",
44
"Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.": "Invalid configuration: can only specify one of default_server_config, default_server_name, or default_hs_url.",
55
"Invalid configuration: no default server specified.": "Invalid configuration: no default server specified.",
66
"Riot Desktop on %(platformName)s": "Riot Desktop on %(platformName)s",

src/vector/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,12 @@ async function loadApp() {
368368

369369
let errorMessage = err.translatedMessage
370370
|| _t("Unexpected error preparing the app. See console for details.");
371-
errorMessage = <span>
372-
{_t(
373-
"This installation of Riot seems to have an invalid server configuration. " +
374-
"If you are the administrator, please correct the error below",
375-
)}
376-
<br />
377-
<br />
378-
{errorMessage}
379-
</span>;
371+
errorMessage = <span>{errorMessage}</span>;
380372

381373
// Like the compatibility page, AWOOOOOGA at the user
382374
const GenericErrorPage = sdk.getComponent("structures.GenericErrorPage");
383375
window.matrixChat = ReactDOM.render(
384-
<GenericErrorPage message={errorMessage} />,
376+
<GenericErrorPage message={errorMessage} title={_t("Your Riot is misconfigured")} />,
385377
document.getElementById('matrixchat'),
386378
);
387379
});
@@ -465,6 +457,11 @@ async function verifyServerConfig() {
465457
// context of email validation. Because we don't respect them otherwise, we do not need
466458
// to parse or consider them here.
467459

460+
// Note: Although we throw all 3 possible configuration options through a .well-known-style
461+
// verification, we do not care if the servers are online at this point. We do moderately
462+
// care if they are syntactically correct though, so we shove them through the .well-known
463+
// validators for that purpose.
464+
468465
const config = SdkConfig.get();
469466
let wkConfig = config['default_server_config']; // overwritten later under some conditions
470467
const serverName = config['default_server_name'];
@@ -486,6 +483,10 @@ async function verifyServerConfig() {
486483

487484
if (hsUrl) {
488485
console.log("Config uses a default_hs_url - constructing a default_server_config using this information");
486+
console.warn(
487+
"DEPRECATED CONFIG OPTION: In the future, default_hs_url will not be accepted. Please use " +
488+
"default_server_config instead.",
489+
);
489490

490491
wkConfig = {
491492
"m.homeserver": {
@@ -507,18 +508,22 @@ async function verifyServerConfig() {
507508

508509
if (serverName) {
509510
console.log("Config uses a default_server_name - doing .well-known lookup");
511+
console.warn(
512+
"DEPRECATED CONFIG OPTION: In the future, default_server_name will not be accepted. Please " +
513+
"use default_server_config instead.",
514+
);
510515
discoveryResult = await AutoDiscovery.findClientConfig(serverName);
511516
}
512517

513-
validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult);
518+
validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult, true);
514519
} catch (e) {
515520
const {hsUrl, isUrl, userId} = Lifecycle.getLocalStorageSessionVars();
516521
if (hsUrl && userId) {
517522
console.error(e);
518523
console.warn("A session was found - suppressing config error and using the session's homeserver");
519524

520525
console.log("Using pre-existing hsUrl and isUrl: ", {hsUrl, isUrl});
521-
validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl);
526+
validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl, true);
522527
} else {
523528
// the user is not logged in, so scream
524529
throw e;

test/app-tests/loading.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ describe('loading:', function() {
240240
uriFragment: "#/room/!room:id",
241241
});
242242

243+
// Pass the liveliness checks
244+
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
245+
httpBackend.when("GET", "/api/v1").respond(200, {});
246+
243247
Promise.delay(1).then(() => {
244248
// at this point, we're trying to do a guest registration;
245249
// we expect a spinner
@@ -277,6 +281,10 @@ describe('loading:', function() {
277281
uriFragment: "#/login",
278282
});
279283

284+
// Pass the liveliness checks
285+
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
286+
httpBackend.when("GET", "/api/v1").respond(200, {});
287+
280288
return awaitLoginComponent(matrixChat).then(() => {
281289
// we expect a single <Login> component
282290
ReactTestUtils.findRenderedComponentWithType(
@@ -285,8 +293,13 @@ describe('loading:', function() {
285293
// the only outstanding request should be a GET /login
286294
// (in particular there should be no /register request for
287295
// guest registration).
296+
const allowedRequests = [
297+
"/_matrix/client/r0/login",
298+
"/versions",
299+
"/api/v1",
300+
];
288301
for (const req of httpBackend.requests) {
289-
if (req.method === 'GET' && req.path.endsWith('/_matrix/client/r0/login')) {
302+
if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) {
290303
continue;
291304
}
292305

@@ -387,6 +400,10 @@ describe('loading:', function() {
387400
});
388401

389402
it('shows a login view', function() {
403+
// Pass the liveliness checks
404+
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
405+
httpBackend.when("GET", "/api/v1").respond(200, {});
406+
390407
// we expect a single <Login> component
391408
ReactTestUtils.findRenderedComponentWithType(
392409
matrixChat, sdk.getComponent('structures.auth.Login'),
@@ -395,8 +412,13 @@ describe('loading:', function() {
395412
// the only outstanding request should be a GET /login
396413
// (in particular there should be no /register request for
397414
// guest registration, nor /sync, etc).
415+
const allowedRequests = [
416+
"/_matrix/client/r0/login",
417+
"/versions",
418+
"/api/v1",
419+
];
398420
for (const req of httpBackend.requests) {
399-
if (req.method === 'GET' && req.path.endsWith('/_matrix/client/r0/login')) {
421+
if (req.method === 'GET' && allowedRequests.find(p => req.path.endsWith(p))) {
400422
continue;
401423
}
402424

@@ -405,6 +427,10 @@ describe('loading:', function() {
405427
});
406428

407429
it('shows the homepage after login', function() {
430+
// Pass the liveliness checks
431+
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
432+
httpBackend.when("GET", "/api/v1").respond(200, {});
433+
408434
return completeLogin(matrixChat).then(() => {
409435
// we should see a home page, even though we previously had
410436
// a stored mx_last_room_id

0 commit comments

Comments
 (0)