AWS Java SDK 1.9.3
When downloading many large files (~3Gb) from AWS S3 in Java server app I get SocketTimeoutException from time to time as following:
Caused by: com.amazonaws.AmazonClientException: Unable to store object contents to disk: Read timed out
at com.amazonaws.services.s3.internal.ServiceUtils.downloadObjectToFile(ServiceUtils.java:270)
at com.amazonaws.services.s3.internal.ServiceUtils.retryableDownloadS3ObjectToFile(ServiceUtils.java:344)
at com.amazonaws.services.s3.transfer.TransferManager$2.call(TransferManager.java:737)
... 4 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:554)
at sun.security.ssl.InputRecord.read(InputRecord.java:509)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:884)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:102)
at org.apache.http.impl.io.AbstractSessionInputBuffer.read(AbstractSessionInputBuffer.java:198)
at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:178)
at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
at com.amazonaws.event.ProgressInputStream.read(ProgressInputStream.java:151)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
at com.amazonaws.event.ProgressInputStream.read(ProgressInputStream.java:151)
at java.security.DigestInputStream.read(DigestInputStream.java:161)
at com.amazonaws.services.s3.internal.DigestValidationInputStream.read(DigestValidationInputStream.java:59)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:73)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at com.amazonaws.services.s3.internal.ServiceUtils.downloadObjectToFile(ServiceUtils.java:265)
... 6 more
I download files from S3 using 4 threads, all threads use the same TransferManager instance. As mantioned before, I'm using AWS SDK 1.9.3 and get such exceptions only from time to time. Code is the following:
...
Download d = transferManager.download(currentBucket, remoteFileName, new File(tmpName));
d.waitForCompletion();
...
Is it an issue of SDK? Maybe of v1.9.3?
And is there any solution except increasing socketTimeout
for ClientConfiguration
?
Here is how I can do in AWS SDK 1.9.3:
ClientConfiguration config = new ClientConfiguration();
config.setConnectionTimeout(connectionTimeout);
config.setSocketTimeout(readTimeout);
AmazonS3 s3 = new AmazonS3Client(credentials, config);
来源:https://stackoverflow.com/questions/28195217/downloading-files-3gb-from-s3-fails-with-sockettimeoutexception-read-timed-ou