aws / aws/aws-sdk-java-v2

`S3AsyncClient#getObject` could complete successfully with no file written to disk

Open
#5,732 5 comments 0 reactions 1 assignee Claimed by @debora-ito View on GitHub
bug p2
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

### Describe the bug

A call to `client.getObject(request, destinationPath)` could complete successfully with no file written to disk. We've seen this in production and was able to write a minimal repro by starting a download, and then manually deleting the file while its being downloaded (for reproduction purposes only, but think a race condition in the business logic) and we could see the future completes successfully.

### Regression Issue

- [ ] Select this option if this issue appears to be a regression.

### Expected Behavior

If no file was written to disk, I'd expect the download future to complete exceptionally - either when the external event that deleted the file occurred, or at least when the download operation completes - at this point it should be able to verify if a file was written to disk or not.

### Current Behavior

The future will complete successfully although no file is written to disk. An application would typically assume if the future completed without exceptions, then the download was successful and a file was written to disk.

### Reproduction Steps

Here is a self contained repo that basically
1\ uploads a 1 GB to
2\ downloads the uploaded file to `/tmp/download/1gb.bin`
3\ 5 seconds after the download starts (at this point, the file is being written to disk) delete the file
4\ few seconds later, the future would complete without and exception

[async-s3-get-object.zip](https://github.com/user-attachments/files/17941018/async-s3-get-object.zip)

To run:
```
unzip async-s3-get-object.zip
cd async-s3-get-object.zip
mvn package
java -jar target/async-s3-get-object-1.0-SNAPSHOT.jar

(for example: java -jar target/async-s3-get-object-1.0-SNAPSHOT.jar XXX XXX "https://s3.amazonaws.com" "us-west-1" "my-test-bucket"
```

You should see the follow log
```
File with 1GB contentLength upload successfully: aym-000-test/1gb.bin
Starting first download attempt: aym-000-test/1gb.bin to /tmp/download/1gb.bin
enforcing a delete after 5 seconds from starting the download
Future completed with no errors, but file not found at: /tmp/download/1gb.bin
```

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### AWS Java SDK version used

2.29.21

### JDK version used

java version "17.0.3.1" 2022-04-22 LTS

### Operating System and version

macOS 14.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.