Skip to content

Set Timeout for watting response #198

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

Closed
lieutandat opened this issue Jan 13, 2019 · 10 comments
Closed

Set Timeout for watting response #198

lieutandat opened this issue Jan 13, 2019 · 10 comments

Comments

@lieutandat
Copy link

lieutandat commented Jan 13, 2019

Hi, I am working with nativescript for both iOS and Android, I tried to set timeout in request with your plugin, however it seem to be not apply at all. I got response code -1 after finish upload file to server few seconds while my server still running process ( will take about 5-6 minutes every request for return response). Could you help me this problem ? Thanks!

@tgpetrov
Copy link
Contributor

Hi @lieutandat,
Can you provide some more information about the desired outcome and also how to reproduce your issue. It will be best if you manage to reproduce it in one of the plugin's demo apps (demo, demo-angular or demo-vue) and let us know the exact steps to follow.

@lieutandat
Copy link
Author

@tgpetrov , Server (Java) receive request api of my team is not public right now, so I can not reproduce backend api.
My frontend

const url = `${path}${uri}/${userId}`;
        var request = {
            url: url,
            method: "POST",
            timeout: 3600000,
            headers: {
                "Content-Type": "application/octet-stream"
            },
            description: "Uploading "
        };
        var params = [ ];
         imagesPaths.forEach(item => {
             params.push({
                 name: item.type, filename: item.imagePath, mimeType: "image/png"
             })
         })
         params.push( { name: "identityDataRequest", value: JSON.stringify(object) })

         return session.multipartUpload(params, request);
       
    }

mybackend (just sample in nodejs, not real java server, it might not work the same as java)

app.post('/identity', (req, res) => {
      console.log(req.body)
      setTimeout(() => {
          res.status(200).send({})
      }, 1000*60);
  });

http.listen('8080', () => {
console.log('We are live on  8080');
});
http.timeout = 1000* 60 *6;
http.keepAliveTimeout =  1000* 60 *6;

when the request completed upload, my server keep request running, but session still return with event errorHandler few seconds (about 15-20s) after upload file completed. I read your plugin code that its does not support timeout attribute. Could you help me to resolve this problem ?

@tgpetrov
Copy link
Contributor

Hi @lieutandat,
Yes, you are right, nativescript-background-http plugins currently doesn't support setting timeout. The android-upload-service we are using on android has its default timeouts set here, but there is a public HTTP_STACK that can be used to set another HurlStack with modified timeouts. On iOS, we using a NSMutableURLRequest that has a timeoutInterval which defaults to 60 seconds.

@lieutandat
Copy link
Author

lieutandat commented Jan 28, 2019

yep @tgpetrov , I trying with added

net.gotev.uploadservice.UploadService.HTTP_STACK = new  net.gotev.uploadservice.http.impl.HurlStack(true, false, 60000, 60000);

in setRequestOptions function and it run perfect.
I will try to change it on iOS and let you know when It successfull. Thank you very much!

@lieutandat
Copy link
Author

Hi @tgpetrov , how can I set retries max times for ios ?

@tgpetrov
Copy link
Contributor

tgpetrov commented Feb 1, 2019

@lieutandat Actually, the 60 seconds timeout that I mentioned earlier seems to be coming from the NSURLSessionConfiguration that we are creating here. The iOS documentation notes here that any task created with this configuration are automatically retried when the request fails due to timeout. There is also a timeoutIntervalForResource, which allows for limiting the time for a specific resource. It seems like combining proper values of these two properties can allow you to limit the number of retries.

@lieutandat
Copy link
Author

Sorry about late reply @tgpetrov, I follow as you mention and it work fine. Thanks you very much!

@ghost ghost removed the feature label Mar 28, 2019
@acharyaks90
Copy link

yep @tgpetrov , I trying with added
net.gotev.uploadservice.UploadService.HTTP_STACK = new net.gotev.uploadservice.http.impl.HurlStack(true, false, 60000, 60000);
in setRequestOptions function and it run perfect.
I will try to change it on iOS and let you know when It successfull. Thank you very much!

Hi @lieutandat where you have added this in plugin code or in nativescript javascript ( own service or component angular).

@lieutandat
Copy link
Author

@acharyaks90 I had to change in plugin code ( setRequestOptions function). This may breach licence law, I do not have more knowledge with Apache license, Does it allow to change plugin source code ?

@acarlstein
Copy link

acarlstein commented Feb 22, 2024

Will you help me? I'm trying to build two applications.

One application requires to create a series of timers.
The other application requires communication with a server to exchange coordinates.

Both applications must work when the app goes in the background, when the user locks the screen, or when the screen goes black.

Could someone please confirm whether setTimeout and setInterval work in the background for iOS and Android?

I'm aware that android might required a permission to be added into the manifest to do so.
I know that iOS requires adding keys/values in the Info.list to do so.

If they do but require extra work, could a link to a tutorial be included? Thank you

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

No branches or pull requests

6 participants