From 8f364985b027dc6516734282e3cc7811bc30599a Mon Sep 17 00:00:00 2001 From: Jan Schmidle Date: Wed, 9 Sep 2020 10:52:07 +0200 Subject: [PATCH 1/3] return void if function is supposed to return nothing currently only for request-execution.js --- lib/request-execution.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/request-execution.js b/lib/request-execution.js index 00cd9a5f1..a25d47705 100644 --- a/lib/request-execution.js +++ b/lib/request-execution.js @@ -115,7 +115,8 @@ class RequestExecution { this._connection = connection; this._host = host; } catch (err) { - return this._parent.handleNoHostAvailable(err, this); + this._parent.handleNoHostAvailable(err, this); + return; } // It could be a new connection from the pool, we should make sure it's in the correct keyspace. @@ -126,7 +127,8 @@ class RequestExecution { } catch (err) { // When its a socket error, attempt to retry. // Otherwise, rethrow the error to the user. - return this._handleError(err, RequestExecution._getErrorCode(err)); + this._handleError(err, RequestExecution._getErrorCode(err)); + return; } } @@ -157,11 +159,12 @@ class RequestExecution { } if (errorCode !== errorCodes.none) { - return this._handleError(errorCode, err); + this._handleError(errorCode, err); + return; } if (response.schemaChange) { - return promiseUtils.toBackground( + promiseUtils.toBackground( this._parent.client .handleSchemaAgreementAndRefresh(this._connection, response.schemaChange) .then(agreement => { @@ -173,6 +176,7 @@ class RequestExecution { this._parent.setCompleted(null, this._getResultSet(response, agreement)); }) ); + return; } if (response.keyspaceSet) { @@ -284,7 +288,8 @@ class RequestExecution { err['coordinator'] = this._host.address; if (errorCode === errorCodes.serverErrorUnprepared) { - return this._prepareAndRetry(err.queryId); + this._prepareAndRetry(err.queryId); + return; } if (errorCode === errorCodes.socketError || errorCode === errorCodes.socketErrorBeforeRequestWritten) { @@ -300,7 +305,8 @@ class RequestExecution { if (this._request instanceof requests.QueryRequest || this._request instanceof requests.ExecuteRequest) { err['query'] = this._request.query; } - return this._parent.setCompleted(err); + this._parent.setCompleted(err); + return; } const metrics = this._parent.client.metrics; @@ -309,12 +315,14 @@ class RequestExecution { metrics.onIgnoreError(err); // Return an empty ResultSet - return this._parent.setCompleted(null, this._getResultSet(utils.emptyObject)); + this._parent.setCompleted(null, this._getResultSet(utils.emptyObject)); + return; } RequestExecution._invokeMetricsHandlerForRetry(errorCode, metrics, err); - return this._retry(decisionInfo.consistency, decisionInfo.useCurrentHost); + this._retry(decisionInfo.consistency, decisionInfo.useCurrentHost); + return; } /** @@ -436,10 +444,12 @@ class RequestExecution { // All connections are busy (`BusyConnectionError`) or there isn't a ready connection in the pool (`Error`) // The retry policy declared the intention to retry on the current host but its not available anymore. // Use the next host - return promiseUtils.toBackground(this.restart()); + promiseUtils.toBackground(this.restart()); + return; } - return this._sendOnConnection(); + this._sendOnConnection(); + return; } // Use the next host in the query plan to send the request in the background @@ -462,15 +472,17 @@ class RequestExecution { const info = this._parent.client.metadata.getPreparedById(queryId); if (!info) { - return this._parent.setCompleted(new errors.DriverInternalError( + this._parent.setCompleted(new errors.DriverInternalError( `Unprepared response invalid, id: 0x${queryId.toString('hex')}`)); + return; } const version = this._connection.protocolVersion; if (!types.protocolVersion.supportsKeyspaceInRequest(version) && info.keyspace && info.keyspace !== connection.keyspace) { - return this._parent.setCompleted( + this._parent.setCompleted( new Error(`Query was prepared on keyspace ${info.keyspace}, can't execute it on ${connection.keyspace} (${info.query})`)); + return; } const self = this; @@ -483,7 +495,8 @@ class RequestExecution { // There was a failure re-preparing on this connection. // Execute the original request on the next connection and forget about the PREPARE-UNPREPARE flow. - return self._retry(undefined, false); + self._retry(undefined, false); + return; } // It's possible that when re-preparing we got new metadata (i.e. if schema changed), update cache. From 4fc6ca10023496dc7eeffaf8b00667f94670121b Mon Sep 17 00:00:00 2001 From: Jan Schmidle Date: Wed, 9 Sep 2020 10:52:58 +0200 Subject: [PATCH 2/3] allow for async error decision making --- lib/request-execution.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/request-execution.js b/lib/request-execution.js index a25d47705..bb7e4f5af 100644 --- a/lib/request-execution.js +++ b/lib/request-execution.js @@ -283,7 +283,7 @@ class RequestExecution { return this._cancelled; } - _handleError(errorCode, err) { + async _handleError(errorCode, err) { this._parent.triedHosts[this._host.address] = err; err['coordinator'] = this._host.address; @@ -299,7 +299,11 @@ class RequestExecution { this._host.checkHealth(this._connection); } - const decisionInfo = this._getDecision(errorCode, err); + let decisionInfo = this._getDecision(errorCode, err); + + if(decisionInfo.then) { + decisionInfo = await decisionInfo; + } if (!decisionInfo || decisionInfo.decision === retry.RetryPolicy.retryDecision.rethrow) { if (this._request instanceof requests.QueryRequest || this._request instanceof requests.ExecuteRequest) { From 8e04906ab2c669d25902fa4d6cc50ddd27e59f25 Mon Sep 17 00:00:00 2001 From: Jan Schmidle Date: Wed, 9 Sep 2020 11:10:35 +0200 Subject: [PATCH 3/3] removed useless return --- lib/request-execution.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/request-execution.js b/lib/request-execution.js index bb7e4f5af..5722f79de 100644 --- a/lib/request-execution.js +++ b/lib/request-execution.js @@ -326,7 +326,6 @@ class RequestExecution { RequestExecution._invokeMetricsHandlerForRetry(errorCode, metrics, err); this._retry(decisionInfo.consistency, decisionInfo.useCurrentHost); - return; } /**