From e0f7f147410d12a7d740778699b309b89e8b5e8b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 1 Feb 2022 16:13:10 +0100 Subject: [PATCH] Instantiate separate S3 session for thread-safety. (#11038) Co-authored-by: Andrew Achkar --- conda/gateways/connection/adapters/s3.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/conda/gateways/connection/adapters/s3.py b/conda/gateways/connection/adapters/s3.py index d1cde2343f5..b766f4b9f6d 100644 --- a/conda/gateways/connection/adapters/s3.py +++ b/conda/gateways/connection/adapters/s3.py @@ -11,7 +11,6 @@ try: import boto3 have_boto3 = True - boto3.client('s3') # https://github.com/conda/conda/issues/8993 except ImportError: try: import boto @@ -54,8 +53,13 @@ def close(self): def _send_boto3(self, boto3, resp, request): from botocore.exceptions import BotoCoreError, ClientError bucket_name, key_string = url_to_s3_info(request.url) - - key = boto3.resource('s3').Object(bucket_name, key_string[1:]) + # https://github.com/conda/conda/issues/8993 + # creating a separate boto3 session to make this thread safe + session = boto3.session.Session() + # create a resource client using this thread's session object + s3 = session.resource('s3') + # finally get the S3 object + key = s3.Object(bucket_name, key_string[1:]) try: response = key.get()