Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

[ios] Request timeout when PUT file to AWS S3 #155

Closed
MQZhangThu opened this issue Oct 14, 2016 · 8 comments
Closed

[ios] Request timeout when PUT file to AWS S3 #155

MQZhangThu opened this issue Oct 14, 2016 · 8 comments

Comments

@MQZhangThu
Copy link

MQZhangThu commented Oct 14, 2016

hi, when I PUT image to AWS S3, sometimes AWS returns error as below: <Error><Code>RequestTimeout</Code><Message>Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.</Message><RequestId>94D59C19C07F4820</RequestId><HostId>QuLF/WaJ5QWW8SdFKIc5e8f0WnNgVFedPz/FPeBcT0pdwfq+hhgYcor0Nggx5qTfON4rHtsGWWSkqybJSUGcFOO5c2dYmP4Y</HostId></Error>.

Sometimes we have this problem, but sometimes not. In my environment, the image is about 3~4MB, with Xcode 8 and iPhone 6 simulator. After some investigation, it seems it is the Content-Length problem. Previously I also opened a relative (maybe) issue #94 (not sure whether they are relative, just FYI).

@wkh237
Copy link
Owner

wkh237 commented Oct 14, 2016

@MQZhangThu , thanks for the information, I assume this is due to the library computed in incorrect Content-Length, such that the server is waiting for more data but the request body has already sent. I'll try to figure out where's the problem.

Besides, is the PUT request a multipart request ?

@MQZhangThu
Copy link
Author

MQZhangThu commented Oct 14, 2016

To be more specific, I use pre-signed url toPUT file to S3, so I think it is not caused by the S3 Services. In my code, I use a loop for to upload 3 images. Code skeleton is as below:

for(let i of ['firstImgSelected', 'secondImgSelected', 'thirdImgSelected']) {
         await RNFetchBlob.fetch('PUT', singedurl[i],
            {'Content-Type' : 'application/octet-stream'},
            RNFetchBlob.wrap(paths[i]))
             .uploadProgress((written, total) => {
                console.log(i, 'uploaded', written/total)
             })
            .then((res)=>{
              /* one image uploaded */
              console.log('one image uploaded', res.text());
           })
}

@MQZhangThu
Copy link
Author

MQZhangThu commented Oct 14, 2016

The image selector used is react-native-image-picker. It is not multipart request, because the image size is below 5MB. In each experiment, one of the 3 images ( sometimes the second one, sometimes the third one) will encounter this error.

2016-10-14 15:41:57.106 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.006895575009685328
2016-10-14 15:42:00.482 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.19307610027118918
2016-10-14 15:42:04.462 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.3103008754358398
2016-10-14 15:42:08.291 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.42752565060049036
2016-10-14 15:42:13.422 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.5516460007748263
2016-10-14 15:42:17.897 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.5930194508329383
2016-10-14 15:42:22.524 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.7102442259975889
2016-10-14 15:42:27.700 [info][tid:com.facebook.react.JavaScript] 'firstImgSelected', ' uploaded ', 0.8274690011622394
2016-10-14 15:42:48.023 [info][tid:com.facebook.react.JavaScript] 'one image uploaded', ''
2016-10-14 15:42:49.526 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.010072119795766624
2016-10-14 15:42:53.861 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.28201935428146546
2016-10-14 15:42:54.920 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.45324539080949805
2016-10-14 15:42:58.878 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.6345435471332973
2016-10-14 15:43:04.013 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.7956974638655633
2016-10-14 15:43:04.312 [info][tid:com.facebook.react.JavaScript] 'secondImgSelected', ' uploaded ', 0.8662023024359297
2016-10-14 15:43:27.159 [info][tid:com.facebook.react.JavaScript] 'one image uploaded', ''
2016-10-14 15:43:30.326 [info][tid:com.facebook.react.JavaScript] 'thirdImgSelected', ' uploaded ', 0.010072119795766624
2016-10-14 15:43:35.458 [info][tid:com.facebook.react.JavaScript] 'thirdImgSelected', ' uploaded ', 0.28201935428146546
2016-10-14 15:43:38.099 [info][tid:com.facebook.react.JavaScript] 'thirdImgSelected', ' uploaded ', 0.36259631264759845
2016-10-14 15:43:43.272 [info][tid:com.facebook.react.JavaScript] 'thirdImgSelected', ' uploaded ', 0.5438944689713977

For the third image, after 0.5438944689713977 progress, we encountered the time out error.

@MQZhangThu
Copy link
Author

@wkh237 To check whether it is content-length problem, I want to pass the content-length Header explicitly ( In this case, my app knows the content-length), as {'Content-Length': 'xxxx'}.

Do I have to modify some other codes in RNFetchBlob module to make this setting effective? I mean, will the RNFetchBlob calculate the length again and over-write it?

@MQZhangThu
Copy link
Author

It seems that It works well for android, as addressed in #94 .
Problem is on IOS.
FYI.

@wkh237
Copy link
Owner

wkh237 commented Oct 14, 2016

I'm not sure if you can overwrite the Content-Length from JS context since it's calculated by the SDK if you're not using Chunked encoding.

@MQZhangThu
Copy link
Author

works well on iPhone devices, rather weird.

@wkh237
Copy link
Owner

wkh237 commented Oct 14, 2016

@MQZhangThu , thank you for the informations 👍 I'm wondering if it only happens when sending reuqests simutaneously, I'll do some test on it.

zombierabbit pushed a commit to zombierabbit/react-native-fetch-blob that referenced this issue Feb 12, 2019
fix progress and uploadProgress not callback in iOS
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants