Skip to content

Conversation

@siddsriv
Copy link
Contributor

@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
*/
retries?: number;
/**
* the number of seconds to sleep in-between retries and/or a customer provided backoff function to call.
Copy link
Contributor

@kuhe kuhe Dec 15, 2025

Choose a reason for hiding this comment

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

docs should say:

If the function returns a promise, it will be awaited and its resolved value ignored.
If the function returns a number, the number will be used as a millisecond duration to wait before the following retry attempt.

await this.backoffFn(attempt);
const backoffResult = this.backoffFn(attempt);
if (typeof backoffResult === "number") {
await this.sleep(backoffResult * 1000); // seconds to milliseconds
Copy link
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?

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