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

Adding retries to most common location service calls #10931

Merged
merged 6 commits into from
Jul 18, 2019

Conversation

shubham90
Copy link
Member

Adding retry to two most common location service calls that shouldn't fail ever on hosted but sometimes does fail because of timeouts:

  1. GetResourceArea call: Gets the packaging utl from collection url
  2. GetConnectionData

try {
return await action();
} catch (error) {
tl.debug(`Network call failed. Number of retries left: ${maxRetries}`);
Copy link

Choose a reason for hiding this comment

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

what would be in the "error" here. anything useful to log for the intermediate retries?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's mostly empty json in the cases I have seen. We are logging the last error in the caller method. Do you still want to log every error from retries?

Copy link

@tkrick tkrick Jul 17, 2019

Choose a reason for hiding this comment

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

if it isn't structured, then i agree better not to log. it would be nice if high level result was logged. status code (or timeout), afdheader if applicable, etc. but probably need to make a change in vss-node-api to do that.

Copy link

Choose a reason for hiding this comment

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

so long as the final result at least looks as good as it does today (it says ECONNRESET, or ETIMEDOUT, 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.

it does, final result is same/better than what it is today.

@@ -94,7 +94,7 @@ export async function getPackagingUris(protocolType: ProtocolType): Promise<Pack

tl.debug('Acquiring Packaging endpoints from ' + serviceUri);

const connectionData = await locationApi.getConnectionData(interfaces.ConnectOptions.IncludeServices);
const connectionData = await retryOnExceptionHelper(() => locationApi.getConnectionData(interfaces.ConnectOptions.IncludeServices), 5, 1000);
Copy link

@tkrick tkrick Jul 17, 2019

Choose a reason for hiding this comment

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

i thought that the node api already does retries under the covers (for known status codes). For these known case does this mean we will now retry 5x5 times (assuming 5 is what is under covers?). If so, maybe we should be less aggressive about these wrapping retries (3 total calls?)

Copy link
Member Author

@shubham90 shubham90 Jul 17, 2019

Choose a reason for hiding this comment

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

Yes, that's correct. I was fighting my mind between 3 and 5. Now that you've said 3, 3 it is.

@@ -37,7 +37,7 @@ export async function getServiceUriFromAreaId(serviceUri: string, accessToken: s

tl.debug(`Getting URI for area ID ${areaId} from ${serviceUri}`);
try {
const serviceUriFromArea = await locationApi.getResourceArea(areaId);
const serviceUriFromArea = await retryOnExceptionHelper(() => locationApi.getResourceArea(areaId), 5, 1000);
Copy link

Choose a reason for hiding this comment

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

is this code used by the nuget authenticate task?

Copy link

Choose a reason for hiding this comment

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

or is there a separate place to update for that?

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 the new one, I am first going to first verify this and then port the code over there.

@@ -150,6 +150,27 @@ export function getWebApiWithProxy(serviceUri: string, accessToken?: string): vs
return new vsts.WebApi(serviceUri, credentialHandler, options);
}

// This function is to apply retries generically for any unreliable network calls
async function retryOnExceptionHelper<T>(action: () => Promise<T>, maxRetries: number, retryIntervalInMilliseconds: number): Promise<T> {
Copy link

Choose a reason for hiding this comment

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

isn't this maxTries not maxRetries? because you first decrement the variable before checking < 1.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! fixed it

@shubham90 shubham90 merged commit 6312b91 into master Jul 18, 2019
@shubham90 shubham90 deleted the users/shbhawsi/addretries branch July 18, 2019 18:50
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.

3 participants