s3 cp exits 0 when an upload fails with ReadTimeoutError (regression since 2.33.0)
Describe the bug
Since 2.33.0, aws s3 cp (classic transfer client) can exit with code 0 even though the upload failed. When the server never responds and the request ends in a ReadTimeoutError after all retries, the failure is not recorded and the command reports success. Nothing is printed to stderr except under --debug.
The failure callback crashes while deciding whether the error is a PreconditionFailed:
Traceback (most recent call last):
File "awscli/s3transfer/futures.py", line 411, in _run_callback
File "awscli/s3transfer/utils.py", line 199, in __call__
File "awscli/customizations/s3/subscribers.py", line 49, in on_done
File "awscli/customizations/s3/results.py", line 130, in _on_failure
File "awscli/customizations/s3/results.py", line 154, in _is_precondition_failed
AttributeError: 'NoneType' object has no attribute 'get'
ReadTimeoutError has a response attribute whose value is None, so hasattr(exception, 'response') is true and exception.response.get(...) raises. _run_callback logs the exception and continues, so no FailureResult is queued and the command exits 0.
In our CI this caused build artifacts that were never uploaded to be treated as uploaded.
Regression Issue
- [x] Select this option if this issue appears to be a regression.
_is_precondition_failed was added in #9750 (first released in 2.33.0). With 2.32.0, the same scenario exits 1 with upload failed: ... Read timeout on endpoint URL.
Expected Behavior
The upload is reported as failed (upload failed: ...) and the command exits non-zero, as in 2.32.0.
Current Behavior
After about 3 minutes (3 attempts × 60 s read timeout), the command exits 0. No upload: line and no upload failed: line are printed.
| Server behavior | 2.32.0 | 2.33.1 | 2.37.9 | 2.37.10 |
|---|---|---|---|---|
| Accepts the request body, never responds | exit 1 | exit 0 | exit 0 | exit 0 |
| Accepts the connection, never reads the body | — | exit 0 | — | — |
| TCP connect timeout | — | exit 1 | — | — |
The same happens for multipart uploads when one UploadPart request times out (exit 0 after the upload is aborted).
Reproduction Steps
A local HTTP server that reads the request body and never responds:
# hang.py
import http.server, time
class H(http.server.BaseHTTPRequestHandler):
def do_PUT(self):
self.rfile.read(int(self.headers.get("Content-Length") or 0))
time.sleep(3600)
def log_message(self, *a): pass
class S(http.server.ThreadingHTTPServer): daemon_threads = True
S(("127.0.0.1", 18901), H).serve_forever()
python3 hang.py &
head -c 1024 /dev/urandom > small.bin
docker run --rm --network host \
-e AWS_ACCESS_KEY_ID=x -e AWS_SECRET_ACCESS_KEY=y -e AWS_DEFAULT_REGION=us-east-1 \
-v "$PWD:/w" public.ecr.aws/aws-cli/aws-cli:2.33.1 \
s3 cp /w/small.bin s3://b/k --endpoint-url http://127.0.0.1:18901
echo "exit=$?" # exit=0 after ~3 minutes
With public.ecr.aws/aws-cli/aws-cli:2.32.0, the same command exits 1.
Possible Solution
Treat a missing or None response as "not a precondition failure", e.g.:
def _is_precondition_failed(self, exception):
response = getattr(exception, 'response', None)
return (
isinstance(response, dict)
and response.get('Error', {}).get('Code') == 'PreconditionFailed'
)
The code is unchanged on the v2 branch as of 2.37.10, and 2.37.10 still reproduces the issue.
Additional Information/Context
aws s3api put-object does not go through this code path and exits 255 in the same scenario.
Related: #1217 reported a similar symptom in 2015 (aws-cli v1, a download cancelled by a read timeout exited 0). The cause here is different: it was introduced in 2.33.0 by #9750.
CLI version used
aws-cli/2.33.1 (also 2.37.9 and 2.37.10; 2.32.0 is not affected)
Environment details (OS name and version, etc.)
Official Docker image public.ecr.aws/aws-cli/aws-cli on Ubuntu 24.04 (x86_64)
Thanks for the detailed regression report and the version-by-version reproduction.
One additional regression boundary seems important here: a transfer failure must never be reported as command success merely because its completion callback raises an exception.
I reviewed the current v2 code paths:
DoneResultSubscriber._on_failure()calls_is_precondition_failed()before enqueuing aFailureResult._is_precondition_failed()dereferencesexception.responsewhen the attribute exists, without checking whether its value is a mapping.TransferCoordinator._run_callback()catches callback exceptions and logs them at debug level.
This means a reporting-layer exception can prevent the transfer failure from reaching the result recorder.
Could the fix include two levels of regression coverage?
- Unit tests for failed futures with
response=None, noresponseattribute, a non-precondition error response, and a genuinePreconditionFailedresponse. Only the genuine precondition case should produceSkipFileResult; other failures should produceFailureResult. - A command-level regression proving that a failed single-part or multipart upload produces an observable failure and a non-zero exit code, even when the original transfer exception has no HTTP response.
More generally, the result-accounting path should fail closed: a callback/reporting error must not turn an unsuccessful transfer into an apparent success.
This is based on source inspection and the published reproduction; I haven't independently executed the AWS CLI tests.