-
Notifications
You must be signed in to change notification settings - Fork 8
Description
The Impersonated client does not currently de-duplicate or cache in-flight promises for access tokens. When background tasks—such as the recently implemented Regional Access Boundary (RAB) refresh—are triggered during getRequestHeaders(), they perform internal requests that recursively call getRequestHeaders().
Since the Impersonated client doesn't de-duplicate these concurrent calls, it results in multiple redundant POST requests to the IAM generateAccessToken endpoint. This is evidenced by the fact that tests in test.impersonated.ts require two IAM nock mocks to pass when RAB is enabled, while only needing one OAuth2 token mock (which is correctly de-duplicated by the source client).
Expected Behavior:
Impersonated client should cache the in-flight token request promise to ensure only one call is made to IAM for concurrent requests.