Aws-sdk-android: pause in TransferUtility seems not work

Created on 3 Mar 2020  路  5Comments  路  Source: aws-amplify/aws-sdk-android

Describe the bug
with code below, value returned by pause is true,
but onProgressChanged in the listener keeps running

in version: 2.11.0, though state FAILED comes up after PAUSED in onStateChanged,
uploading task stop properly.

To Reproduce

TransferObserver uploadObserver = getS3Utility(context).upload(
        //...
);
uploadObserver.setTransferListener(getmTransferListener(this));

start an upload via above method, then pause by its id like

getS3Utility(aContext).pause(taskId); // taskId is equal to uploadObserver.getId()

Which AWS service(s) are affected?
com.amazonaws:aws-android-sdk-s3:2.16.8
com.amazonaws:aws-android-sdk-mobile-client:2.16.8

Expected behavior
when pause method is triggered, uploading task stop

Environment Information (please complete the following information):

  • AWS Android SDK Version:2.16.8
  • Device: Pixel 3
  • Android Version: 10
  • Specific to simulators: No
Bug S3

Most helpful comment

Hi @gcobc12677,

Thank you for reporting this issue to us. I managed to reproduce the bug when trying to pause a multipart upload. I will investigate the issue to apply a fix for it as soon as possible.

All 5 comments

Hi @gcobc12677 ,

Thank you for taking time to report the issue. To allow us to assist you better, would you be able to provide the relevant code snippet where you are setting up the TransferUtility as well as the log at the time of transfer failure?

below is how I get instances of AmazonS3 and TransferUtility

private static AmazonS3 s3Client = null;
private static TransferUtility s3Utility = null;

private static AmazonS3 getS3Client() {
    if (s3Client == null) {
        BasicAWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);

        s3Client = Observable.create(
                (ObservableOnSubscribe<AmazonS3>) emitter -> {
                    s3Client = new AmazonS3Client(
                            credentials,
                            Region.getRegion(Regions.AP_NORTHEAST_1)
                    );
                    emitter.onNext(s3Client);
                    emitter.onComplete();
                })
                .singleElement()
                .blockingGet();
    }
    return s3Client;
}

private static TransferUtility getS3Utility(Context applicationContext) {
    if (s3Utility == null) {
        TransferNetworkLossHandler.getInstance(applicationContext);
        s3Utility = TransferUtility
                .builder()
                .context(applicationContext)
                .s3Client(getS3Client())
                .build();
    }

    return s3Utility;
}

then upload file this way

Observable.just(TEST_FILE_NAME)
    // ...
    .flatMap(file -> {
        // upload file with listeners
        Context context = getApplicationContext();
        TransferObserver uploadObserver = getS3Utility(context).upload(
                BUCKET,
                PREFIX + "/" + file.getName(),
                file
        );
        uploadObserver.setTransferListener(getmTransferListener(this));
        // ...

        return Observable.just(true);
    })
    .subscribeOn(Schedulers.newThread())
    .subscribe();

moreover, transfer listener is look like (appendLog just be used for logging)

private class MTransferListener implements TransferListener {
    private Context context;

    MTransferListener(Context context) {
        this.context = context;
    }

    @Override
    public void onStateChanged(int id, TransferState state) {
        String hintStr = String.format("[%s] onStateChanged %s", id, state.toString());
        appendLog(hintStr);
        switch (state) {
            case COMPLETED:
            case CANCELED:
                removeTask(context, id);
                break;
        }
    }

    @Override
    public void onProgressChanged(
            int id,
            long bytesCurrent,
            long bytesTotal
    ) {
        appendLog(String.format(Locale.getDefault(),
                "[%s] onProgressChanged %d/%d",
                id,
                bytesCurrent,
                bytesTotal
        ));
    }

    @Override
    public void onError(int id, Exception ex) {
        Timber.e(ex, "[%s] onError", id);
    }
}

finally, I try to pause task

Context aContext = getApplicationContext();
int currentId = getCurrentId(aContext);
if (currentId >= 0) {
    getS3Utility(aContext).pause(currentId);
}

currentId is equal to uploadObserver.getId()

here is log
onStateChanged PAUSED had shown up
but onProgressChanged keep been triggered

2020-03-09 12:26:12.803 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 31457280/52428800
2020-03-09 12:26:12.909 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 32505856/52428800
2020-03-09 12:26:12.930 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 33554432/52428800
2020-03-09 12:26:12.946 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 34603008/52428800
2020-03-09 12:26:13.064 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 35651584/52428800
2020-03-09 12:26:13.078 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 36700160/52428800
2020-03-09 12:26:13.094 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 37748736/52428800
2020-03-09 12:26:13.110 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 38797312/52428800
2020-03-09 12:26:13.114 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 39845888/52428800
2020-03-09 12:26:13.126 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 40894464/52428800
2020-03-09 12:26:13.143 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 41943040/52428800
2020-03-09 12:26:13.163 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.163 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.163 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.164 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.168 22595-22686/com.example.uploadtest D/AmazonS3Client: Using path style addressing. Endpoint = https://s3.ap-northeast-1.amazonaws.com
2020-03-09 12:26:13.168 22595-22686/com.example.uploadtest D/AmazonS3Client: Key: android_test/50MB.zip; Request: PUT https://s3.ap-northeast-1.amazonaws.com /nsd.dev/android_test/50MB.zip 
2020-03-09 12:26:13.170 22595-22686/com.example.uploadtest D/AWS4Signer: AWS4 Canonical Request: '"PUT
    /nsd.dev/android_test/50MB.zip
    partNumber=10&uploadId=rZSx481_cIw8VIQQnOA5gtuQTQOVeIxyAdXiFXtN9LL78HqTjTJkL_XNC77DT1rw8MhR.2qemFTzceDsG1pYePEJVpDpMt2ZuxH5u0I9DNht6UMsN6BfhwCG.B9kgaXW7W7rwLhGqEhgFcxRHG6Oww--
    host:s3.ap-northeast-1.amazonaws.com
    x-amz-content-sha256:STREAMING-AWS4-HMAC-SHA256-PAYLOAD
    x-amz-date:20200309T032613Z
    x-amz-decoded-content-length:5242880

    host;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length
    STREAMING-AWS4-HMAC-SHA256-PAYLOAD"
2020-03-09 12:26:13.170 22595-22686/com.example.uploadtest D/AWS4Signer: AWS4 String to Sign: '"AWS4-HMAC-SHA256
    20200309T032613Z
    20200309/ap-northeast-1/s3/aws4_request
    8a787036c8008794c6c620f5ccb2ec03164fe40cbc3dbc740ce17c98963d83f5"
2020-03-09 12:26:13.190 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 42991616/52428800
2020-03-09 12:26:13.208 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 44040192/52428800
2020-03-09 12:26:13.225 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 45088768/52428800
2020-03-09 12:26:13.230 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 46137344/52428800
2020-03-09 12:26:13.236 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 47185920/52428800
2020-03-09 12:26:13.273 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 48234496/52428800
2020-03-09 12:26:13.293 22595-22688/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.293 22595-22688/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.293 22595-22688/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.293 22595-22688/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.298 22595-22680/com.example.uploadtest E/UploadTask: Upload resulted in an exception. java.lang.InterruptedException
2020-03-09 12:26:13.298 22595-22680/com.example.uploadtest I/UploadTask: Transfer is PAUSED
2020-03-09 12:26:13.299 22595-22595/com.example.uploadtest D/MainActivity: [512] onStateChanged PAUSED
2020-03-09 12:26:13.312 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 49283072/52428800
2020-03-09 12:26:13.380 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 50331648/52428800
2020-03-09 12:26:13.525 22595-22690/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.525 22595-22690/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.525 22595-22690/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.526 22595-22690/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.555 22595-22685/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.556 22595-22685/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.556 22595-22685/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.556 22595-22685/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.627 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 51380224/52428800
2020-03-09 12:26:13.632 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.632 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.632 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.632 22595-22686/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.635 22595-22687/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.635 22595-22687/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.635 22595-22687/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.635 22595-22687/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.649 22595-22693/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.649 22595-22693/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.649 22595-22693/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.649 22595-22693/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.745 22595-22692/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:13.746 22595-22692/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:13.746 22595-22692/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:13.746 22595-22692/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:13.827 22595-22595/com.example.uploadtest D/MainActivity: [512] onProgressChanged 52428800/52428800
2020-03-09 12:26:14.076 22595-22689/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:14.077 22595-22689/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:14.077 22595-22689/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:14.077 22595-22689/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.
2020-03-09 12:26:14.349 22595-22691/com.example.uploadtest D/S3MetadataResponseHandl: Server is ignored.
2020-03-09 12:26:14.350 22595-22691/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-request-id is ignored.
2020-03-09 12:26:14.350 22595-22691/com.example.uploadtest D/S3MetadataResponseHandl: x-amz-id-2 is ignored.
2020-03-09 12:26:14.350 22595-22691/com.example.uploadtest D/S3MetadataResponseHandl: Date is ignored.

Hi @gcobc12677,

Thank you for reporting this issue to us. I managed to reproduce the bug when trying to pause a multipart upload. I will investigate the issue to apply a fix for it as soon as possible.

The fix to address this issue is now merged and will be shipped with our upcoming v2.16.11 release.

Was this page helpful?
0 / 5 - 0 ratings