Skip to content

Commit

Permalink
Fix boto3 initialization race condition (conda#9037)
Browse files Browse the repository at this point in the history
Fix boto3 initialization race condition
  • Loading branch information
msarahan authored Aug 2, 2019
2 parents 5c66306 + e5276d2 commit c150add
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions conda/gateways/connection/adapters/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
from logging import LoggerAdapter, getLogger
from tempfile import SpooledTemporaryFile

have_boto3 = have_boto = False
try:
import boto3
have_boto3 = True
boto3.client('s3') # https://github.com/conda/conda/issues/8993
except ImportError:
try:
import boto
have_boto = True
except ImportError:
pass

from .. import BaseAdapter, CaseInsensitiveDict, Response
from ....common.compat import ensure_binary
from ....common.url import url_to_s3_info
Expand All @@ -24,21 +36,17 @@ def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxi
resp = Response()
resp.status_code = 200
resp.url = request.url

try:
import boto3
if have_boto3:
return self._send_boto3(boto3, resp, request)
except ImportError:
try:
import boto
return self._send_boto(boto, resp, request)
except ImportError:
stderrlog.info('\nError: boto3 is required for S3 channels. '
'Please install with `conda install boto3`\n'
'Make sure to run `source deactivate` if you '
'are in a conda environment.\n')
resp.status_code = 404
return resp
elif have_boto:
return self._send_boto(boto, resp, request)
else:
stderrlog.info('\nError: boto3 is required for S3 channels. '
'Please install with `conda install boto3`\n'
'Make sure to run `source deactivate` if you '
'are in a conda environment.\n')
resp.status_code = 404
return resp

def close(self):
pass
Expand Down

0 comments on commit c150add

Please sign in to comment.