Skip to content
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

Transfer manager fails silently #3868

Closed
gadelkareem opened this issue Sep 21, 2023 · 1 comment
Closed

Transfer manager fails silently #3868

gadelkareem opened this issue Sep 21, 2023 · 1 comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.

Comments

@gadelkareem
Copy link

Describe the bug

Transfer Manager fails to upload file however, it does not provide any errors.

Expected Behavior

botocore.errorfactory.NoSuchBucket should be thrown

Current Behavior

Example outputs:

# with tqdm
❯ python3 ./bug.py || echo failed
  0%|          | 0.00/4.00 [00:01<?, ?B/s]upload

# no tqdm
❯ python3 ./bug.py || echo failed
(no output)

# boto3.set_stream_logger('')
❯ python3 ./bug.py || echo failed
2023-09-22 01:12:05,845 botocore.parsers [DEBUG] Response body:
b'<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message><BucketName>non-existing-bucket</BucketName><RequestId>x</RequestId><HostId>x</HostId></Error>'
2023-09-22 01:12:05,848 botocore.parsers [DEBUG] Response headers: {'x-amz-request-id': 'x', 'x-amz-id-2': 'x', 'Content-Type': 'application/xml', 'Transfer-Encoding': 'chunked', 'Date': 'Thu, 21 Sep 2023 23:12:05 GMT', 'Server': 'AmazonS3', 'Connection': 'close'}
2023-09-22 01:12:05,848 botocore.parsers [DEBUG] Response body:
b'<?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>NoSuchBucket</Code><Message>The specified bucket does not exist</Message><BucketName>non-existing-bucket</BucketName><RequestId>x</RequestId><HostId>x</HostId></Error>'
2023-09-22 01:12:05,848 botocore.hooks [DEBUG] Event needs-retry.s3.PutObject: calling handler <bound method RetryHandler.needs_retry of <botocore.retries.standard.RetryHandler object at 0x104dd6560>>
2023-09-22 01:12:05,849 botocore.retries.standard [DEBUG] Not retrying request.
2023-09-22 01:12:05,849 botocore.hooks [DEBUG] Event needs-retry.s3.PutObject: calling handler <bound method S3RegionRedirectorv2.redirect_from_error of <botocore.utils.S3RegionRedirectorv2 object at 0x104dd65f0>>
2023-09-22 01:12:05,849 botocore.hooks [DEBUG] Event after-call.s3.PutObject: calling handler <bound method RetryQuotaChecker.release_retry_quota of <botocore.retries.standard.RetryQuotaChecker object at 0x104dd60b0>>
2023-09-22 01:12:05,849 s3transfer.tasks [DEBUG] Exception raised.
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/tasks.py", line 139, in __call__
    return self._execute_main(kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/tasks.py", line 162, in _execute_main
    return_value = self._main(**kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/upload.py", line 758, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/botocore/client.py", line 980, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist
2023-09-22 01:12:05,859 s3transfer.utils [DEBUG] Releasing acquire 0/None
2023-09-22 01:12:05,859 s3transfer.utils [DEBUG] Releasing acquire 0/None

Reproduction Steps

Using Transfer Manger:

import os
import boto3
from botocore.config import Config
from boto3.s3.transfer import TransferConfig, create_transfer_manager, ProgressCallbackInvoker, S3Transfer
from tqdm import tqdm

local_path = "/tmp/test"
transfer_config = TransferConfig(
    max_concurrency=1,
    use_threads=False,
)
botocore_config = Config(
    max_pool_connections=1,
    retries={
        'max_attempts': 1,
        'mode': 'standard'
    }
)
# boto3.set_stream_logger('')

s3_client = boto3.client('s3', config=botocore_config)
transfer_manager = create_transfer_manager(s3_client, transfer_config)

total_size = os.path.getsize(local_path)
progress = tqdm(
    desc='upload',
    total=total_size, unit='B', unit_scale=1,
    position=0,
    bar_format='{percentage:3.0f}%|{bar:10}{r_bar}{desc:<10}')

transfer_manager.upload(local_path, 'non-existing-bucket', 'test',
                        subscribers=[
                            ProgressCallbackInvoker(progress.update),
                        ]
                        )

Possible Solution

Using S3Tranfer directly fails with exception:

import os
import boto3
from botocore.config import Config
from boto3.s3.transfer import TransferConfig, create_transfer_manager, ProgressCallbackInvoker, S3Transfer
from tqdm import tqdm

local_path = "/tmp/test"
transfer_config = TransferConfig(
    max_concurrency=1,
    use_threads=False,
)
botocore_config = Config(
    max_pool_connections=1,
    retries={
        'max_attempts': 1,
        'mode': 'standard'
    }
)
# boto3.set_stream_logger('')

s3_client = boto3.client('s3', config=botocore_config)
transfer_manager = S3Transfer(s3_client, transfer_config)

total_size = os.path.getsize(local_path)
progress = tqdm(
    desc='upload',
    total=total_size, unit='B', unit_scale=1,
    position=0,
    bar_format='{percentage:3.0f}%|{bar:10}{r_bar}{desc:<10}')

transfer_manager.upload_file(local_path, 'non-existing-bucket', 'test',
                             callback=ProgressCallbackInvoker(progress.update))

Output:

❯ python3 ./bug.py || echo failed
  0%|          | 0.00/4.00 [00:00<?, ?B/s]upload    Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/boto3/s3/transfer.py", line 292, in upload_file
    future.result()
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/futures.py", line 103, in result
    return self._coordinator.result()
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/futures.py", line 266, in result
    raise self._exception
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/tasks.py", line 139, in __call__
    return self._execute_main(kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/tasks.py", line 162, in _execute_main
    return_value = self._main(**kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/s3transfer/upload.py", line 758, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/botocore/client.py", line 535, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/botocore/client.py", line 980, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./bug.py", line 31, in <module>
    transfer_manager.upload_file(local_path, 'non-existing-bucket', 'test',
  File "/opt/homebrew/anaconda3/envs/PythonScripts/lib/python3.10/site-packages/boto3/s3/transfer.py", line 298, in upload_file
    raise S3UploadFailedError(
boto3.exceptions.S3UploadFailedError: Failed to upload /tmp/test to non-existing-bucket/test: An error occurred (NoSuchBucket) when calling the PutObject operation: The specified bucket does not exist
  0%|          | 0.00/4.00 [00:01<?, ?B/s]upload
failed

Additional Information/Context

No response

SDK version used

boto3==1.28.52

Environment details (OS name and version, etc.)

macos, docker

@gadelkareem gadelkareem added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Sep 21, 2023
@gadelkareem
Copy link
Author

Nevermind.

r = transfer_manager.upload(local_path, 'non-existing-bucket', 'test',
                        subscribers=[
                            ProgressCallbackInvoker(progress.update),
                        ]
                        )
# check exceptions
r.result() 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant