Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketTimeoutException: Read timed out problem #119

Closed
tosulc opened this issue Apr 8, 2016 · 11 comments
Closed

SocketTimeoutException: Read timed out problem #119

tosulc opened this issue Apr 8, 2016 · 11 comments
Labels
question General question

Comments

@tosulc
Copy link

tosulc commented Apr 8, 2016

Hello.

I'm simulating bad network environment (with Genymotion - GPRS network). When trying to send an image using TransferUtility upload method, I'm getting (after some 15 seconds) an error in logcat:

04-08 10:28:49.673 28521-32477/com.tom.example I/AmazonHttpClient: Unable to execute HTTP request: Read timed out
  java.net.SocketTimeoutException: Read timed out
      at com.android.org.conscrypt.NativeCrypto.SSL_read(Native Method)
      at com.android.org.conscrypt.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:699)
      at com.android.okio.Okio$2.read(Okio.java:113)
      at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:147)
      at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:94)
      at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:179)
      at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
      at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:628)
      at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
      at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
      at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseMessage(HttpURLConnectionImpl.java:496)
      at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getResponseMessage(DelegatingHttpsURLConnection.java:109)
      at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getResponseMessage(HttpsURLConnectionImpl.java:25)
      at com.amazonaws.http.UrlHttpClient.createHttpResponse(UrlHttpClient.java:72)
      at com.amazonaws.http.UrlHttpClient.execute(UrlHttpClient.java:66)
      at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:353)
      at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:196)
      at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4204)
      at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1618)
      at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.uploadSinglePartAndWaitForCompletion(UploadTask.java:174)
      at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:74)
      at com.amazonaws.mobileconnectors.s3.transferutility.UploadTask.call(UploadTask.java:40)
      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
      at java.lang.Thread.run(Thread.java:818)

In my code, I have a sync mechanism that occur after pull to refresh on some screens. It collects unsynced data and when syncing photos, I use response from aws sdk to determine if the photo is synced or not.
To make things worse, my image in this case (when simulating bad network) do come to the aws folder correctly, but aws sdk is giving me TransferState.FAILED for the TransferObserver object so my sync mechanism will again collect that photo to sync.

When I get back to "normal" connection, aws will get back TransferState.COMPLETED and my sync mechanism will now know that the picture did upload correctly, even though it already exists on Amazon S3.

Is there a way to set a longer period for timeout? Or handle this somehow?

Thanks.

@fosterzhang
Copy link
Contributor

@tomkhan Increase socket timeout via ClientConfiguration.setSocketTimeout(int).

@fosterzhang fosterzhang added the question General question label Apr 8, 2016
@tosulc
Copy link
Author

tosulc commented Apr 11, 2016

@fosterzhang Thanks for your help.

But I'm pretty sure that there is some problem in the SDK with this. Because, even though I get that SocketTimeoutException and my inner logic (after that) stops trying to send that picture, some background thread in your SDK is still sending the image and it comes to my server correctly, even though that exception is thrown.

@fosterzhang
Copy link
Contributor

@tomkhan I noticed some issue with interrupting an ongoing transfer. Trying to improve it. Stay tuned.

@fosterzhang
Copy link
Contributor

@tomkhan This should be fixed in v2.2.16. For detailed changes, please refer to the change log.

@tosulc
Copy link
Author

tosulc commented May 11, 2016

Hi @fosterzhang how can I update it to that version?

My current gradle configuration has this:
compile 'com.amazonaws:aws-android-sdk-s3:2.2.9'
What's the newer version? Did you update it there?

@fosterzhang
Copy link
Contributor

@tomkhan The latest version is 2.2.16. Please update 2.2.9 to 2.2.16.

@tosulc
Copy link
Author

tosulc commented May 11, 2016

Oh. I forgot that the two digit numbers are going after one digit numbers (kidding, was thinking that you were incrementing from the right side, like 91 :))

Thank @fosterzhang will try and get back here.

@tosulc
Copy link
Author

tosulc commented May 13, 2016

@fosterzhang I'm afraid it didn't help.

I've put the old code back, removed the timeout:
ClientConfiguration cc = new ClientConfiguration(); cc.setSocketTimeout(120000); AmazonS3 s3 = new AmazonS3Client(credentialsProvider, cc);

Initialized with only:
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);

And updated gradle with:
compile 'com.amazonaws:aws-android-sdk-s3:2.2.16'

When I try to send picture to my web (first I upload its thumb, then the original picture), there is no longer that old warning, but this:
05-13 16:32:06.078 14815-16180/com.example.app D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences 05-13 16:32:06.078 14815-16180/com.example.app D/CognitoCachingCredentialsProvider: No valid credentials found in SharedPreferences 05-13 16:32:07.522 14815-14815/com.example.app D/TransferSerivce: Starting Transfer Service 05-13 16:32:07.526 14815-14815/com.example.app D/TransferSerivce: Network connected: true 05-13 16:32:07.554 14815-16271/com.example.app D/TransferSerivce: Loading transfers from database 05-13 16:32:07.554 14815-16271/com.example.app D/TransferSerivce: 0 transfers are loaded from database 05-13 16:32:07.582 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences 05-13 16:32:07.582 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: No valid credentials found in SharedPreferences 05-13 16:32:14.482 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: Identity id is changed 05-13 16:32:14.482 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: Saving identity id to SharedPreferences 05-13 16:32:14.482 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: Clearing credentials from SharedPreferences 05-13 16:32:15.694 14815-16272/com.example.app D/CognitoCachingCredentialsProvider: Saving credentials to SharedPreferences 05-13 16:32:16.314 14815-16272/com.example.app E/UploadTask: Failed to upload: 1 due to Unable to execute HTTP request: null 05-13 16:32:48.254 14815-16480/com.example.app E/UploadTask: Failed to upload: 2 due to Unable to execute HTTP request: Read timed out

After some time, both pictures get to my server and are shown there, but the mobile is showing an error because TransferObserver is saying upload failed.

@fosterzhang
Copy link
Contributor

@tomkhan is there a reliable way to reproduce it? What I don't understand is that the upload succeeded eventually while the state said no. If you are on a relatively poor network, I suggest your increase socket timeout.

What I changed in the latest version is that transfer service does a check of network status when socket time out occurs and will change the transfer to waiting for network if network is indeed out. When the upload is marked as failed, that really means some unresolvable network issue and the upload won't complete itself.

@tosulc
Copy link
Author

tosulc commented May 15, 2016

I can only reproduce it with Genymotion simulating GPRS network. When sending large picture (3+ MB), that timeout occurs will give me failed response (also, I forgot to mention, I'm using this solution to check the state #91). But somehow, it will complete the upload in the background (knowing this by the picture visible on the server in a minute or two).

For now, increasing socket timeout is the solution.

@alokipandey
Copy link

alokipandey commented Mar 2, 2021

I also had this issue and I resolved it while going through multiple stackoverflow /github /aws doc pages. leaving a link to my documentation below for whomsoever may need it.
https://alokipandey.medium.com/upload-to-aws-s3-from-android-s3-integration-customizations-for-large-files-f7b8e2c35b3c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question
Projects
None yet
Development

No branches or pull requests

3 participants