HENNGE / aiodynamo

Asynchronous, fast, pythonic DynamoDB Client
https://aiodynamo.readthedocs.io/
Other
69 stars 20 forks source link

Fix timing bug in Refreshable, optimize ChainCredentials #168

Closed ojii closed 8 months ago

ojii commented 8 months ago

Refreshable had a timing bug where refreshing the token could result in an invalid state if invalidate() was called at the same time. This is due to the Event Loop being able to schedule other coroutines to run between the current value being set in _refresh() and the value being checked in get(). By moving the assignment from _refresh() to get(), no other coroutines can run between the setting and checking, preventing the class from ending up in an invalid state.

ChainCredentials would needlessly check many candidates every time, even if it had already done so previously. Since running code cannot move to different environments, this check is unneccessary and inefficient, so instead ChainCredentials now remembers when a provider has succeeded and will only try that one again.