Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uploadPart is failing with Unable to execute HTTP request: Connection reset

I am trying to perform a file upload using multipart upload AWS S3 java API (I am using SDK 1.8.1). I am able to perform the upload successfully.

But, intermittently I keep getting this exception.

Jul 31, 2014 4:39:38 AM com.amazonaws.http.AmazonHttpClient executeHelper INFO: Unable to execute HTTP request: Connection reset java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:189) at java.net.SocketInputStream.read(SocketInputStream.java:121) at sun.security.ssl.InputRecord.readFully(InputRecord.java:312) at sun.security.ssl.InputRecord.read(InputRecord.java:350) 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.fillBuffer(AbstractSessionInputBuffer.java:166) at org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:90) at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:281) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:62) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:254) at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:289) at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:252) at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:191) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300) at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doReceiveResponse(SdkHttpRequestExecutor.java:66) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127) at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:717) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:522) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:402) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:245) at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3711) at com.amazonaws.services.s3.AmazonS3Client.uploadPart(AmazonS3Client.java:2809) at cloud.<-filename->.writeContent(<-filename->.java:<-linenumber->)

at the following code

try {
                  _partETags.add(_s3.uploadPart(uploadPartReq).getPartETag());
      } catch (AmazonClientException e) {
                  System.out.println("Amazon service error. Retrying...");
                  printException(e);
      } catch (Exception e) {
                  printException(e);
                  throw new UserException("Received an exception while performing upload part");
      }

If I look at the docuementation, it says that uploadPart function will throw only two classes AmazonClientException and AmazonServiceException.

Link: http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3.html#uploadPart(com.amazonaws.services.s3.model.UploadPartRequest)

<documentation>
...
UploadPartResult uploadPart(UploadPartRequest request)
throws AmazonClientException,
AmazonServiceException
...
Throws:
AmazonClientException - If any errors are encountered in the client while making the request or handling the response.
AmazonServiceException - If any errors occurred in Amazon S3 while processing the request. 
...
</documentation>

But, I am receiving at different exception.

I have the following questions

  • Is this an expected behavior, if not how do I fix this issue?
  • Why is my try catch block not able to catch this exception ?
  • In the case of AmazonClient or AmazonServiceException, is it recommended that we retry the upload again or should these be considered as non-recoverable errors ?
like image 240
samanasrikanth Avatar asked Nov 10 '22 03:11

samanasrikanth


1 Answers

That's a log message (at the INFO level) from the AmazonS3Client telling you there was a transient network error. By default, the AmazonS3Client catches these kinds of exceptions and retries the upload for you. You can tweak this behavior via ClientConfiguration. If the upload has still not succeeded after the configured number of retries, an AmazonClientException will be thrown, as per the documentation.

like image 137
David Murray Avatar answered Nov 14 '22 22:11

David Murray