Skip to content

feat(ec2-metadata-service): add retries for IMDS requests#7569

Merged
siddsriv merged 3 commits intomainfrom
mds-retries
Dec 16, 2025
Merged

feat(ec2-metadata-service): add retries for IMDS requests#7569
siddsriv merged 3 commits intomainfrom
mds-retries

Conversation

@siddsriv
Copy link
Copy Markdown
Collaborator

@siddsriv siddsriv commented Dec 11, 2025

Issue

Internal JS-5193

Description

Support retries for EC2 IMDS requests and fetching tokens.

Testing

Unit tests:

 ✓ src/MetadataService.spec.ts (24 tests) 20ms
   ✓ MetadataService Socket Leak Checks > fetchMetadataToken - body consumption checks > should consume response body on 200 status and return token 5ms
   ✓ MetadataService Socket Leak Checks > fetchMetadataToken - body consumption checks > should consume response body on 400 status before throwing 2ms
.
.
.

   ✓ MetadataService Retry Configuration > status code handling for retries > should not retry 403 errors 0ms
   ✓ MetadataService Retry Configuration > status code handling for retries > should not retry 404 errors 0ms
   ✓ MetadataService Retry Configuration > status code handling for retries > should retry 401 errors 0ms
   ✓ MetadataService Retry Configuration > status code handling for retries > should retry 500 errors 0ms

 Test Files  1 passed (1)
      Tests  24 passed (24)
   Start at  23:37:49
   Duration  354ms (transform 72ms, setup 0ms, collect 96ms, tests 20ms, environment 0ms, prepare 78ms)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@siddsriv siddsriv requested a review from a team as a code owner December 11, 2025 23:41
@siddsriv siddsriv changed the title feat(ec2-metadata-service): add retries feat(ec2-metadata-service): add retries for IMDS requests Dec 11, 2025
Comment thread packages/ec2-metadata-service/src/MetadataService.ts
Comment thread packages/ec2-metadata-service/src/MetadataService.spec.ts
Comment thread packages/ec2-metadata-service/src/MetadataService.ts Outdated
Comment thread packages/ec2-metadata-service/src/MetadataService.ts Outdated
Comment thread packages/ec2-metadata-service/src/MetadataServiceOptions.ts
await this.backoffFn(attempt);
const backoffResult = this.backoffFn(attempt);
if (typeof backoffResult === "number") {
await this.sleep(backoffResult * 1000); // seconds to milliseconds
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.

use milliseconds for time, since that is the time unit idiomatic to the language? how is the specification on this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

spec and the docs here indicate seconds as the ground truth

*/
disableFetchToken?: boolean;
/**
* the number of retry attempts for any failed request, defaulting to 3.
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.

default attempt count = 4 then?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, 1 initial + 3 retries (by default)

@siddsriv siddsriv merged commit 4b9a0ea into main Dec 16, 2025
7 checks passed
@siddsriv siddsriv deleted the mds-retries branch December 16, 2025 23:47
@github-actions
Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Dec 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants