Skip to content

Transient failure retries - #574

Merged
tvrprasad merged 3 commits into
tediousjs:masterfrom
tvrprasad:transient-failure-retries
May 12, 2017
Merged

tvrprasad merged 3 commits into
tediousjs:masterfrom
tvrprasad:transient-failure-retries

Conversation

@tvrprasad

Copy link
Copy Markdown
Contributor

@arthurschreiber @chdh This adds retries for transient failures that all Microsoft drivers do to improve reliability. This could address some of the connection failures issues that have been reported over time.

@tvrprasad

Copy link
Copy Markdown
Contributor Author

Some tests failing on Linux for NodeJS 4. Error suggests issue with machine state than code:

Failed to connect to localhost:1433 in 15000ms

Is there some way to retrigger the test without submitting a dummy change?

@tvrprasad

Copy link
Copy Markdown
Contributor Author

I made a dummy PR (#575) with the same changes which triggered a re-run and tests pass now.

@@ -0,0 +1,17 @@
class TransientErrorLookup {

@chdh chdh May 9, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is the isTransientError() function within a class?
Why is it in a separate JS file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes it easier and cleaner to stub it out in the tests. Add a comment to clarify that.

Comment thread src/transient-error-lookup.js Outdated
// - https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlInternalConnectionTds.cs#L115
const transientErrors = [4060, 10928, 10929, 40197, 40501, 40613];

for (let j = 0; j < transientErrors.length; j++) {

@chdh chdh May 9, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not use Array.indexOf()? It's available in the current Node 4 version (4.8.3).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/connection.js Outdated
const isLoginErrorTransient = this.transientErrorLookup.isTransientError(token.number);
if (isLoginErrorTransient && this.curTransientRetryCount !== this.config.options.maxRetriesOnTransientErrors) {
this.debug.log('Initiating retry on transient error = ', token.number);
return this.transitionTo(this.STATE.TRANSIENT_FAILURE_RETRY);

@chdh chdh May 9, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The "return" statements with a value are an artefact of the CoffeeScript to JavaScript conversion and should not be used where it makes no sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.
Added a clean-up item to remove these across the board - #576

Comment thread src/connection.js
}
} else {
const isLoginErrorTransient = this.transientErrorLookup.isTransientError(token.number);
if (isLoginErrorTransient && this.curTransientRetryCount !== this.config.options.maxRetriesOnTransientErrors) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Better use < than !== for comparing a retry count.

Comment thread src/connection.js
const port = this.routingData ? this.routingData.port : this.config.options.port;
this.debug.log('Retry after transient failure connecting to ' + server + ':' + port);

return this.dispatchEvent('retry');

@chdh chdh May 9, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not just call createRetryTimer() here? dispatchEvent() is executed synchronously and there is no transition to another state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that'd make it harder to follow the logic. Now it's easy to see what's happening by looking at code under TRANSIENT_FAILURE_RETRY and back track from there.

@@ -0,0 +1,20 @@
const TransientErrorLookup = require('../../src/transient-error-lookup').TransientErrorLookup;

@chdh chdh May 9, 2017 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test case seems very superfluous to me for such a simple function as isTransientError(). Otherwise you better write a test case for the test case in this case... :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes it even more silly now that I changed the code to indexOf :-)
This is just an assertion to make sure any additions or deletion from list of transient errors is intentional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

btw, this test actually caught a bug when I switched to Array.indexOf per your suggestion. I had return transientErrors.indexOf(error) === -1; where I should have return transientErrors.indexOf(error) !== -1; and this test failed.

test.expect(config.options.maxRetriesOnTransientErrors + 1);

this.sinon.stub(TransientErrorLookup.prototype, 'isTransientError', () => {
return true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not test for the error code for "invalid password" here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tvrprasad tvrprasad left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@chdh Thanks for the feedback.

Comment thread src/connection.js Outdated
const isLoginErrorTransient = this.transientErrorLookup.isTransientError(token.number);
if (isLoginErrorTransient && this.curTransientRetryCount !== this.config.options.maxRetriesOnTransientErrors) {
this.debug.log('Initiating retry on transient error = ', token.number);
return this.transitionTo(this.STATE.TRANSIENT_FAILURE_RETRY);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.
Added a clean-up item to remove these across the board - #576

Comment thread src/connection.js
const port = this.routingData ? this.routingData.port : this.config.options.port;
this.debug.log('Retry after transient failure connecting to ' + server + ':' + port);

return this.dispatchEvent('retry');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that'd make it harder to follow the logic. Now it's easy to see what's happening by looking at code under TRANSIENT_FAILURE_RETRY and back track from there.

@@ -0,0 +1,17 @@
class TransientErrorLookup {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This makes it easier and cleaner to stub it out in the tests. Add a comment to clarify that.

Comment thread src/transient-error-lookup.js Outdated
// - https://github.com/dotnet/corefx/blob/master/src/System.Data.SqlClient/src/System/Data/SqlClient/SqlInternalConnectionTds.cs#L115
const transientErrors = [4060, 10928, 10929, 40197, 40501, 40613];

for (let j = 0; j < transientErrors.length; j++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

test.expect(config.options.maxRetriesOnTransientErrors + 1);

this.sinon.stub(TransientErrorLookup.prototype, 'isTransientError', () => {
return true;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,20 @@
const TransientErrorLookup = require('../../src/transient-error-lookup').TransientErrorLookup;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes it even more silly now that I changed the code to indexOf :-)
This is just an assertion to make sure any additions or deletion from list of transient errors is intentional.

@tvrprasad

Copy link
Copy Markdown
Contributor Author

@chdh Addressed/responded to your comments. If you don't have more comments I'll commit this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants