aws-sdk-java: com.amazonaws.AmazonClientException: Unable to complete transfer: Task java.util.concurrent.FutureTask@fb8627a rejected from java.util.concurren

com.amazonaws.AmazonClientException: Unable to complete transfer: Task java.util.concurrent.FutureTask@fb8627a rejected from java.util.concurrent.ThreadPoolExecutor@34a22437[Shutting down, pool size = 6, active threads = 6, queued tasks = 0, completed tasks = 0] at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.unwrapExecutionException(AbstractTransfer.java:281) at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.rethrowExecutionException(AbstractTransfer.java:265) at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.waitForCompletion(AbstractTransfer.java:103) at com.alacriti.reports.etl.service.S3FileDAO.pushToS3(S3FileDAO.java:49) at com.alacriti.reports.etl.service.EtlFilesManagerService.rotateFiles(EtlFilesManagerService.java:184) at com.alacriti.reports.etl.service.EtlFilesManagerService.run(EtlFilesManagerService.java:111) at java.lang.Thread.run(Thread.java:748) Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@fb8627a rejected from java.util.concurrent.ThreadPoolExecutor@34a22437[Shutting down, pool size = 6, active threads = 6, queued tasks = 0, completed tasks = 0] at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047) at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at com.amazonaws.services.s3.transfer.internal.UploadCallable.uploadPartsInParallel(UploadCallable.java:295) at com.amazonaws.services.s3.transfer.internal.UploadCallable.uploadInParts(UploadCallable.java:188) at com.amazonaws.services.s3.transfer.internal.UploadCallable.call(UploadCallable.java:123) at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:139) at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:47) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) … 1 more

We are running this process, which pushes files into S3, for every 5 minutes. This is a sequential task and nowhere, it tries to push 2 files simultaneously.

I wonder , why is this TransferManager is getting shutdown all of a sudden. sdks used: aws-java-sdk-s3-1.11.76.jar aws-java-sdk-kms-1.11.76.jar aws-java-sdk-core-1.11.75.jar

code

	PutObjectRequest putRequest = new PutObjectRequest(this.bucketName, this.key, file)
					.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(this.kmsKey));

			TransferManager tm = new TransferManager(s3Client);
			Upload upload = tm.upload(putRequest);
                          upload .waitForCompletion();


About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

This issue is due to a fundamental flaw in how TransferManager works. Typically the flow is a TransferManager is created, then a method that returns something that implements Transfer is returned. eg. TransferManager.downloadDirectory returns a MultipleFileDownload. Calling code then calls downloader.waitForCompletion on the MultipleFileDownload object. At this point its also typical for no other reference to TransferManager exist, allowing it to be garbage collected, but unfortunately TransferManager has a finalizer that destroys the ThreadPool which causes Transfer.waitForCompletion() to blow up IMPORTANT: The GC only considers references it does not consider scope. Thus even through TransferManager may still be in scope it can be garbage collected, unless there is future code references it.

A workaround is to add a line of logging that references TransferManager AFTER the call to waitForCompletion() call. This will prevent the TransferManager being garbage collected before the transfer has completed.

eg.

upload.waitForCompletion(); Log.info(“Logging to keep a reference to TransferManager:” + mgr.hashCode());

AWS could fix this by adding a reference to the TransferManager in all implementations of Transfer, such as MultipleFileDownload etc. This would also prevent the TransferManager being garbage collected, while it’s still in use. I wish AWS would fix this. It’s crazy it’s behaved like this for so long.

We encountered the same RejectedExecutionException here. But a little different. In our scenario, we create a new TransferManager every time once a file download request was submitted. We fix our issue with calling transferManager.shutdownNow(false); right after download.waitForCompletion() Since we found out that hundreds of s3-transfer-manager-worker thread are up and waiting for GC in the background. I write here to see if this could help anyone.

Hi @shorea , Everytime we want to push file to S3, we are creating AmazonS3 object and passing it to TransferManager.

this.s3Client = AmazonS3ClientBuilder.standard().withRegion(region).build();
PutObjectRequest putRequest = new PutObjectRequest(this.bucketName, this.key, file)
					.withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(this.kmsKey));

			TransferManager tm = new TransferManager(s3Client);
			Upload upload = tm.upload(putRequest);
                          upload .waitForCompletion();


For every 5 minutes, we push around 2-5 files to S3.

We got this error again today, after 22 Sep, when this question is posted.