-
Notifications
You must be signed in to change notification settings - Fork 421
[Thread-safety] Concurrent instantiation of Boto3 clients #1718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
hey @dispyfree thanks a lot for flagging this, agree, our oversight (not sure why we did this way) -- if you have the bandwidth, I'd appreciate a PR on this while I deal with unrelated issues, so I can make it part of this week's release on time (fine to make a patch release next week too if we can't). |
Just remembered why that was done - lazy initialisation to ease testing. If it was an existing session it could've even thread-safe. |
Had a quick look into this and it needs a deeper investigation - Boto3 client is thread-safe, when using a Session, however we use the higher level client called For now:
This will highly likely be tackled after re:Invent or in January given PTOs, etc. If anyone else reading this has the bandwidth to implement it along with a functional test to certify the behaviour we'll gladly accept any PR. |
This is now released under 2.3.0 version! |
@mploski checking in for an update/ETA when you think you might be able to start working on this. Thanks a lot! |
@heitorlessa I've already started working on this but was occupied by other activities, unfortunately. Plan to open the PR by the end of the week :-) |
|
Hey @dispyfree, fixes related to issue raised here were merged and will be released soon. Thank you for your contribution. |
Expected Behaviour
The decorator
idempotent_function
should be thread-safe. In particular, consumers of the library should not have to worry about threading issues in the underlying library.In particular, the code snippet provided below should run without errors.
Current Behaviour
AWS Powertools instantiates boto3 client objects concurrently. While boto3 client objects are thread-safe, their instantiation is not.
Hence, we see exceptions like the following:
Code snippet
Possible Solution
Simply instantiating the client as part of the persistance layer itself, instead of re-instantiating the client upon access of the property mitigates the problem to a large part. In particular, the chance of collisions is reduced greatly. In particular, if thread instantiation itself is sequentially done, then this already mitigates the problem entirely.
This is a patch for DynamoDBPersistanceLayer:
Steps to Reproduce
(see code snippet above - "minimal breaking example" )
AWS Lambda Powertools for Python version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: