Skip to content

[core-rest-pipeline] Bug Fix - Retry logic to honor abort signal #20781

Merged
HarshaNalluru merged 12 commits intoAzure:mainfrom
HarshaNalluru:harshan/issue/20778
Mar 11, 2022
Merged

[core-rest-pipeline] Bug Fix - Retry logic to honor abort signal #20781
HarshaNalluru merged 12 commits intoAzure:mainfrom
HarshaNalluru:harshan/issue/20778

Conversation

@HarshaNalluru
Copy link
Copy Markdown
Contributor

@HarshaNalluru HarshaNalluru commented Mar 10, 2022

Packages impacted by this PR

  • @azure/core-rest-pipeline
  • And any packages that depend on the retry logic implemented in the core-rest-pipeline. (Basically, every SDK)

Issues associated with this PR

Fixes #20778

Describe the problem that is addressed by this PR

Retry logic in core-rest-pipeline doesn't honor abort signal.

Found while investigating #20766
Added a new delay method that takes in abort options, Using the new delay method in the place of the older delay method in the retry logic.

Are there test cases added in this PR? (If not, why?)

Yes

Checklists

  • Added impacted package name to the issue description
  • Added a changelog (if necessary)

@ghost ghost added the Azure.Core label Mar 10, 2022
Comment thread sdk/core/core-rest-pipeline/CHANGELOG.md Outdated
Comment thread sdk/core/core-rest-pipeline/test/throttlingRetryPolicy.spec.ts Outdated
Comment thread sdk/core/core-rest-pipeline/package.json
`Retry ${retryCount}: Retry strategy ${strategy.name} retries after ${retryAfterInMs}`
);
await delay(retryAfterInMs);
await delay(retryAfterInMs, undefined, { abortSignal: request.abortSignal });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It always feels cumbersome to have to pass in undefined in the middle. Can we make value (or valueToResolve) part of the options bag?

Copy link
Copy Markdown
Contributor Author

@HarshaNalluru HarshaNalluru Mar 11, 2022

Choose a reason for hiding this comment

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

Should I put everything in the options bag instead?
I feel the "value" is more important and it is better to not put it in the options bag.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

my impression is that only the first parameter is used most of time. But no strong feeling. This is not public.

* @param value - The value to be resolved with after a timeout of t milliseconds.
* @returns Resolved promise
* @param options - The options for delay - currently abort options
* @param abortSignal - The abortSignal associated with containing operation.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does tsdoc/jsdoc work in this way for nested properties?

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.

Hmmm, doesn't look good.

Updated to
image

Ok now?

Comment thread sdk/core/core-rest-pipeline/CHANGELOG.md Outdated
*/
export function delay<T>(t: number, value?: T): Promise<T | void> {
return new Promise((resolve) => setTimeout(() => resolve(value), t));
export function delay<T>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t know if the delay function is the best place to put this code.
However, I understand why it would make sense to put it in the delay code.
So I think it’s ok!

Do we have other examples of the delay function handling the abort signal?
I wonder if this is going to be a pattern moving forward.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this delay function with abortSignal support be in core-rest-pipelines or perhaps in another core package?

Copy link
Copy Markdown
Contributor Author

@HarshaNalluru HarshaNalluru Mar 11, 2022

Choose a reason for hiding this comment

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

I have not written this from scratch, this was from core-http.

And we also have a similar(identical) method in core-amqp and service-bus also relies on it I think.

Basically, it's already prior art for a few years now and I'm not introducing any new patterns.

Copy link
Copy Markdown
Contributor Author

@HarshaNalluru HarshaNalluru Mar 11, 2022

Choose a reason for hiding this comment

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

Should this delay function with abortSignal support be in core-rest-pipelines or perhaps in another core package?

@sadasant It is now added in core-rest-pipeline.
I would prefer core-util, but it is not a dependency of core-rest-pipeline.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Anyway, I like the design! A lot! Just food for thought.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ohh I understand now! Alright

Copy link
Copy Markdown
Member

@deyaaeldeen deyaaeldeen left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Copy link
Copy Markdown
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for the fix!

Copy link
Copy Markdown
Contributor

@sadasant sadasant left a comment

Choose a reason for hiding this comment

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

Let’s go!

@HarshaNalluru HarshaNalluru enabled auto-merge (squash) March 11, 2022 20:09
@HarshaNalluru HarshaNalluru merged commit 08004eb into Azure:main Mar 11, 2022
@HarshaNalluru HarshaNalluru deleted the harshan/issue/20778 branch March 12, 2022 00:47
@xirzec
Copy link
Copy Markdown
Member

xirzec commented Mar 14, 2022

I was surprised to see we never ported this from core-http -- apparently this was hanging out on our backlog this whole time: #16118 😅

@HarshaNalluru
Copy link
Copy Markdown
Contributor Author

Oh damn, thanks for pointing out, @xirzec! It was so old that I didn't even realize I logged that issue. 😂

WeiJun428 pushed a commit to WeiJun428/azure-sdk-for-js that referenced this pull request Mar 20, 2022
…re#20781)

* throttlingRetryPolicy should honor abort signal

* puppeteer for browser tests

* changelog

* Update sdk/core/core-rest-pipeline/CHANGELOG.md

* update jsdoc

* changelog

* assert.isRejected

* lint:fix

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[core-rest-pipeline] Retry logic doesn't honor abort signal

5 participants