I/O error during system call, Connection reset by peer issue with S3 client

15,237

Solution 1

The solution is to retry the request.

Connection reset by peer theoretically means the far end server reset the connection, due to a fault in the communication or an internal error, though in practice, intermediate equipment (particularly firewalls and NAT/PAT devices) can also craft a response packet that generates this same error.

Usually this though be interpreted as a consequence of traffic traversing the Internet -- sometimes things go wrong, outside your control.

This condition should only indicate you're doing something wrong (something you can correct) if the same request repeatedly throws an error while other requests are succeeding.

Solution 2

I was having the same error but it was due to time difference between the Android devices and the server (time skew).

When I started messing around with the time and timezone of the device I found a pattern to reproduce this same error (it was not random, with a certain date and timezone on the device the upload/download always failed).

If this is your case, the fix is to use the s3client.setTimeOffset() to correct the time skew between the devices and the s3 server.

Edit:

This is how I changed the time skew on the device code:

amazonS3Client.setTimeOffset(getTimeSkew());
...
private int getTimeSkew() {
    long dif = (new Date()).getTime() - TimeHelper.getUTCTimeInMillis();
    return (int)(dif/(long)1000);
}

In the method getUTCTimeInMillis() I get the time from an external server that I know it returns current time in UTC.

Hope it helps.

Solution 3

Also important to note regarding the very unforgiving upload API of S3 - if you use POST instead of PUT you will get this horrible SSL error, when you should be getting 405 Method not allowed which will clearly explain what went wrong.

Bottom line: make sure you use PUT when uploading to S3

Share:
15,237
Bao Le
Author by

Bao Le

Software Engineer

Updated on July 05, 2022

Comments

  • Bao Le
    Bao Le almost 2 years

    I got this exception occasionally when try to upload files (image, audio) to S3. Is there any solution for this?

    Configuration: Android 4x, 5x, aws-android-sdk-s3 version 2.2.14.

    Unable to execute HTTP request: Write error: ssl=0x9ab52680: I/O error during system call, Connection reset by peer
    javax.net.ssl.SSLException: Write error: ssl=0x9ab52680: I/O error during system call, Connection reset by peer
        at com.android.org.conscrypt.NativeCrypto.SSL_write(Native Method)
        at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:766)
        at com.android.okhttp.okio.Okio$1.write(Okio.java:76)
        at com.android.okhttp.okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
        at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
        at com.android.okhttp.okio.RealBufferedSink.write(RealBufferedSink.java:46)
        at com.android.okhttp.internal.http.HttpConnection$FixedLengthSink.write(HttpConnection.java:302)
        at com.android.okhttp.okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.java:176)
        at com.android.okhttp.okio.RealBufferedSink$1.write(RealBufferedSink.java:198)
        at com.amazonaws.http.UrlHttpClient.write(UrlHttpClient.java:172)
        at com.amazonaws.http.UrlHttpClient.writeContentToConnection(UrlHttpClient.java:129)
        at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:65)
        at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:360)
        at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:199)
        at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4221)
        at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1628)
        at net.tandem.ext.aws.AmazonUtil.uploadFile(AmazonUtil.java:131)
        at net.tandem.ext.aws.AmazonUtil.uploadFile(AmazonUtil.java:65)
        at net.tandem.service.MessageService$2.doInBackground(MessageService.java:323)
        at net.tandem.service.MessageService$2.doInBackground(MessageService.java:315)
        at android.os.AsyncTask$2.call(AsyncTask.java:295)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
    
  • snehasish
    snehasish about 7 years
    how to change timezone ? can you help me ?
  • SebaGra
    SebaGra about 7 years
    I edited my answer with the code that I used to calculate the time offset in the client.
  • snehasish
    snehasish about 7 years
    I am getting this error Unable to execute HTTP request: Write error: ssl=0xb79c18d8: I/O error during system call, Connection reset by peer
  • SebaGra
    SebaGra about 7 years
    Yes, that is the same error I got. Try to vary the timeOffset or change the timezone on the device settings to figure out what is the time skew you are having. Also do check this post: stackoverflow.com/questions/30565422/…
  • snehasish
    snehasish about 7 years
    rt now its showing progress is 100% but at the end state is failed.. can you please help me ..
  • Blue
    Blue over 6 years
    I've noticed that you added another question at the bottom of your answer. This section is just for answers. You can search for similar questions, or refer to the related and linked questions on the right-hand side of the page to find an answer. If you have a related but different question, ask a new question, and include a link to this one to help provide context. See: Ask questions, get answers, no distractions.
  • luckyging3r
    luckyging3r over 2 years
    I can't find documentation for this. We've been trying to test out POSTs to get a 405 to make sure we are handling errors correctly but we've been getting this SSL and/or broken pipe error. There doesn't seem to be any documentation