From c6a18b11f046e17ce262890717f12a97dadb75bd Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 14 Jul 2019 23:23:48 -0600 Subject: [PATCH 1/2] Check for liveliness on submission when the server was previously dead Fixes https://github.com/vector-im/riot-web/issues/10017 Specifically the `return` at the end of the diff fixes the problem, but it seems worthwhile to check for liveliness when we know the server has been dead in previous attempts. --- src/components/structures/auth/Login.js | 28 ++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index a7bd8ba2ab..6a34a7651e 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -145,9 +145,31 @@ module.exports = React.createClass({ return this.state.busy || this.props.busy; }, - onPasswordLogin: function(username, phoneCountry, phoneNumber, password) { - // Prevent people from submitting their password when something isn't right. - if (this.isBusy()) return; + onPasswordLogin: async function(username, phoneCountry, phoneNumber, password) { + if (!this.state.serverIsAlive) { + this.setState({busy: true}); + // Do a quick liveliness check on the URLs + try { + await AutoDiscoveryUtils.validateServerConfigWithStaticUrls( + this.props.serverConfig.hsUrl, + this.props.serverConfig.isUrl, + ); + this.setState({serverIsAlive: true, errorText: ""}); + } catch (e) { + this.setState({ + busy: false, + ...AutoDiscoveryUtils.authComponentStateForError(e), + }); + if (this.state.serverErrorIsFatal) { + return; // Server is dead - do not continue. + } + } + + // Prevent people from submitting their password when something isn't right. + if (!this.state.serverIsAlive) { + return; + } + } this.setState({ busy: true, From 2bc0e8e1519c59ff1af4d085285b3f9b5e420147 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 15 Jul 2019 10:51:08 -0600 Subject: [PATCH 2/2] Don't rely on React being fast --- src/components/structures/auth/Login.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/structures/auth/Login.js b/src/components/structures/auth/Login.js index 6a34a7651e..27378447d5 100644 --- a/src/components/structures/auth/Login.js +++ b/src/components/structures/auth/Login.js @@ -149,6 +149,7 @@ module.exports = React.createClass({ if (!this.state.serverIsAlive) { this.setState({busy: true}); // Do a quick liveliness check on the URLs + let aliveAgain = true; try { await AutoDiscoveryUtils.validateServerConfigWithStaticUrls( this.props.serverConfig.hsUrl, @@ -156,17 +157,16 @@ module.exports = React.createClass({ ); this.setState({serverIsAlive: true, errorText: ""}); } catch (e) { + const componentState = AutoDiscoveryUtils.authComponentStateForError(e); this.setState({ busy: false, - ...AutoDiscoveryUtils.authComponentStateForError(e), + ...componentState, }); - if (this.state.serverErrorIsFatal) { - return; // Server is dead - do not continue. - } + aliveAgain = !componentState.serverErrorIsFatal; } // Prevent people from submitting their password when something isn't right. - if (!this.state.serverIsAlive) { + if (!aliveAgain) { return; } }