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

Amazon SDK createHttpResponse Crash #108

Closed
gintechsystems opened this issue Mar 3, 2016 · 8 comments
Closed

Amazon SDK createHttpResponse Crash #108

gintechsystems opened this issue Mar 3, 2016 · 8 comments
Labels
question General question wontfix This may be a valid issue but is accepted as a known defect or existing behavior.

Comments

@gintechsystems
Copy link

I constantly receive the following crash in Crashlytics for Android, anyway to resolve or any information on why this would be happening? I am thinking maybe related to timeout, but I have tried increasing that and it had no effect.

com.amazonaws.http.UrlHttpClient.createHttpResponse

@fosterzhang
Copy link
Contributor

Would you please provide stacktrace? If possible, please explain how to reproduce it, including environment, SDK version, and code snippet.

@fosterzhang fosterzhang added the question General question label Mar 3, 2016
@gintechsystems
Copy link
Author

Fatal Exception: com.amazonaws.AmazonClientException: Unable to execute HTTP request: null at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:421) 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.droid.visneta.NetworkQueue$3.run(NetworkQueue.java:637) at java.lang.Thread.run(Thread.java:818) Caused by java.io.EOFException at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:98) at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:202) at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:119) at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:795) 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.droid.visneta.NetworkQueue$3.run(NetworkQueue.java:637) at java.lang.Thread.run(Thread.java:818)

@gintechsystems
Copy link
Author

I cannot reproduce myself not not sure. I am using Android Studio. The SDK is com.amazonaws:aws-android-sdk-s3:2.2.13.

@gintechsystems
Copy link
Author

               ObjectMetadata metadata = new ObjectMetadata();
                metadata.setContentEncoding("UTF-8");
                try {
                    metadata.setContentLength(currImageStream.available());
                } catch (IOException e) {
                    e.printStackTrace();
                    starterRealmThread.close();
                    return;
                }

                //The image length is less than or equal to 0, retry uploading this image later.
                if (metadata.getContentLength() <= 0) {
                    starterRealmThread.close();
                    return;
                }

                Log.d("Content-Length", String.valueOf(metadata.getContentLength()));
                currImageTask.setTotalBytes(metadata.getContentLength());

                String assetDate = DateTime.now().toString("yyyy/MM/dd");
                if (currImageTask.getPhoto().getOrderPhotoAssetDate() != null) {
                    assetDate = AppUtils.formatTimestampS3ToDateTime(currImageTask.getPhoto().getOrderPhotoAssetDate());
                }

                String fileExtension = imagePath.substring(imagePath.lastIndexOf('.') + 1);
                final String remoteFilePath = "uploads/" + assetDate + "/" + visnetawrap.visnetaUser.userId + "/" + currImageTask.getPhoto().getOrderPhotoId() + "." + fileExtension;

                PutObjectRequest por = new PutObjectRequest("vnimages", remoteFilePath, currImageStream, metadata);
                por.setCannedAcl(CannedAccessControlList.PublicReadWrite);
                por.setGeneralProgressListener(new ProgressListener() {
                    @Override
                    public void progressChanged(ProgressEvent progressEvent) {
                        if (progressEvent.getEventCode() == ProgressEvent.COMPLETED_EVENT_CODE) {
                            Realm realmThread = Realm.getDefaultInstance();
                            realmThread.executeTransaction(new Realm.Transaction() {
                                @Override
                                public void execute(Realm realm) {
                                    ImageQueueTask completedImageTask = realm.where(ImageQueueTask.class).equalTo("id", imageId).findFirst();

                                    completedImageTask.setRemoteFilePath(remoteFilePath);
                                    completedImageTask.setStatus(QueueTaskStatus.getQueueTaskStatusNumber(QueueTaskStatus.QueueTaskStatusComplete));
                                    completedImageTask.setStatusReason("Completed");
                                    completedImageTask.setProcessDate(new Date());

                                    QueueTask currTask = realm.where(QueueTask.class).equalTo("id", "wo" + currWORawId).findFirst();
                                    //currTask.setStatus(QueueTaskStatus.getQueueTaskStatusNumber(QueueTaskStatus.QueueTaskStatusProcessingSubtasks));
                                    //currTask.setStatusReason("ProcessingSubtasks");
                                    JsonObject currTaskCompletionDict = new Gson().fromJson(currTask.getCompletionDict(), JsonObject.class);
                                    currTaskCompletionDict.addProperty("current_image_index", currImageTaskIndex + 1);
                                    currTask.setCompletionDict(new Gson().toJson(currTaskCompletionDict));

                                }
                            });
                            realmThread.close();

                            imageQueueTask(currImageTaskIndex + 1, currWORawId);

                            //Close stream after the photo has been uploaded to fix a possible crash.
                            try {
                                currImageStream.close();
                            }
                            catch (IOException e) {
                                e.printStackTrace();
                            }

                            Log.d("S3Manager", "Image uploaded - " + remoteFilePath);
                        }
                        else if (progressEvent.getEventCode() == ProgressEvent.FAILED_EVENT_CODE) {
                            Realm realmThread = Realm.getDefaultInstance();
                            realmThread.executeTransaction(new Realm.Transaction() {
                                @Override
                                public void execute(Realm realm) {
                                    ImageQueueTask completedImageTask = realm.where(ImageQueueTask.class).equalTo("id", imageId).findFirst();

                                    completedImageTask.setRemoteFilePath(remoteFilePath);
                                    completedImageTask.setStatus(QueueTaskStatus.getQueueTaskStatusNumber(QueueTaskStatus.QueueTaskStatusError));
                                    completedImageTask.setStatusReason("Error");

                                    QueueTask currTask = realm.where(QueueTask.class).equalTo("id", "wo" + currWORawId).findFirst();
                                    currTask.setStatus(QueueTaskStatus.getQueueTaskStatusNumber(QueueTaskStatus.QueueTaskStatusError));
                                    currTask.setStatusReason("Error");
                                }
                            });
                            realmThread.close();

                            Log.d("S3Manager", "Image " + remoteFilePath + "failed to upload.");
                        }
                        else {
                            //int currProgress = (int) (currImageTask.getTotalBytes() / currImageTask.getCurrentBytesTransferred());
                            //Log.d("S3Manager", "Image Progress: " + String.valueOf(progressEvent.getBytesTransferred()));
                        }
                    }
                });
                visnetawrap.s3Client.putObject(por);

@fosterzhang
Copy link
Contributor

@gintechsystems Looks like it's a bug related to okhttp, the default implementation of HttpURLConnection since Android 4.4 KitKat API level 19. It may occur on some devices running some Android versions. See square/okhttp#1114. It's out of the control of the SDK unfortunately.

@fosterzhang fosterzhang added the wontfix This may be a valid issue but is accepted as a known defect or existing behavior. label Mar 9, 2016
@gintechsystems
Copy link
Author

Hmm ok, I recently switched from using their library because it caused me to many issues. So I assume when I get a crash it is related to an older version of the app. I will look at the issue # you posted. Thanks.

@nativ18
Copy link

nativ18 commented May 16, 2017

So we basically have nothing to do with it but accept this bug or what other option there is?

@gintechsystems
Copy link
Author

gintechsystems commented May 18, 2017

Unless okhttp has fixed this issue since then, yeah it is still an issue. I haven't tested this in a long time to know for sure. Workaround I used the built-in android tools instead of okhttp. I also had to work around an SSL bug in Android 4.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General question wontfix This may be a valid issue but is accepted as a known defect or existing behavior.
Projects
None yet
Development

No branches or pull requests

3 participants