5
votes

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 ?
2
I am seeing the same thingSomeone Somewhere

2 Answers

1
votes

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.

0
votes

While i was trying to upload my project AWS lambda via eclipse, I followed the steps from the tutorial link:

https://examples.javacodegeeks.com/software-development/amazon-aws/tutorial-use-aws-lambda-s3-real-time-data-processing/

But while working on the step "Deploy Lambda code to AWS" ===> In Eclipse, right click your code and select Amazon Web Services > Upload function to Lambda…

Errors I faced : 1) I got an error window with the message "Failed to upload project to Lambda Unable to execute HTTP request: Connection reset by peer: socket write error"

2) First Line of my Stack Tarce for an exception was : "com.amazonaws.SdkClientException: Unable to execute HTTP request: Connection reset by peer: socket write error Caused by: java.net.SocketException: Connection reset by peer: socket write error"

3) Eclipse error log was giving the message : "java.lang.NullPointerException at org.eclipse.core.databinding.ValueBinding.doUpdate(ValueBinding.java:158)"

Then i changed the setting by making a small change in my eclipse network connection, since my proxy setting was blocking to upload my project to lambda, i came up with the solution as follows:

Solution : Window -> Preferences -> General -> Network Connection -> Active Provider as "Direct".

And then tried to upload the project on lambda by using the same steps, and it worked for me. Hope this will help you too.