Skip to content

Race condition in credential management when reusing same session across tasks #1455

@leoleoasd

Description

@leoleoasd

Describe the bug
A clear and concise description of what the bug is.

I'm reusing same session in multiple tasks and concurrently launching them. my aws config looks like:

[profile a]
role_arn = xxx
source_profile= b

[profile b]
role_arn = xxx
credential_source = Ec2InstanceMetadata

and got this error:

Infinite loop in credential configuration detected. Attempting to load from profile yuxuanlu which has already been visited. Visited profiles: ['a', 'b'];

My suspicion is first task is accessing a then b, and marking b as visited, and second task encountered error when visiting b as well. Maybe a global lock is needed for credential management. I added an STS call before launching my tasks (so credentials are fetched and cached) and no longer seeing the issue:

async with self.boto_session.client("sts", region_name=self.region) as sts:
    identity = await sts.get_caller_identity()
    print(f"Caller identity: {identity}")

Checklist

  • I have reproduced in environment where pip check passes without errors
  • I have provided pip freeze results
  • I have provided sample code or detailed way to reproduce
  • I have tried the same code in botocore to ensure this is an aiobotocore specific issue
  • I have tried similar code in aiohttp to ensure this is is an aiobotocore specific issue
  • I have checked the latest and older versions of aiobotocore/aiohttp/python to see if this is a regression / injection

pip freeze results

Environment:

  • Python Version: 3.13.2
  • OS name and version: linux

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions