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

[Bug] [Android] Timeout argument ignored, global argument taken #471

Open
ZweiEuro opened this issue Jun 19, 2022 · 6 comments
Open

[Bug] [Android] Timeout argument ignored, global argument taken #471

ZweiEuro opened this issue Jun 19, 2022 · 6 comments

Comments

@ZweiEuro
Copy link

Describe the bug
My app makes 2 kinds of http calls:
To a local device which needs 1s timeout in order to quickly detect if it is down.
To a server which needs 10s timeout to work reliably since that can take longer than 1s.

I wanted to avoid setting the timeout globally with
this.http.setRequestTimeout(...);
But when I set it only via the argumetns of:
.sendRequest(...,{... timeout:1});
Its ignored. If a timeout occurs it's always exactly after 60 seconds which is the default.

Setting the global default will overwrite it for all requests.

This makes me think that the argument of the sendrequest timeout is ignored in general and only the global argument is taken.

System info

  • affected HTTP plugin version: 3.1.0
  • affected platform(s) and version(s): Android 11
  • affected device(s): Fairphone 4
  • cordova version: 6.19.0
  • cordova platform version(s): Android 9.1.0

Are you using ionic-native-wrapper?
No, at least i can't find it anywhere in package.json or in config.xml of the app.

Minimum viable code to reproduce

  this.platform.ready().then(async () => {
      // Test timeout bug

      let now = new Date().getTime();

      // will timeout in 60s since that is globally default
      await this.http
        .sendRequest("http://192.168.123.32", {
          method: "get",
          responseType: "blob",
          timeout: 1,
        })
        .then((data) => {
          console.error("Success", data);
        })
        .catch((error) => {
          console.error("timeout after: ", new Date().getTime() - now, "ms", error);
        });

      this.http.setRequestTimeout(2);

      now = new Date().getTime();

      // will timeout in 2s since that is globally default now, both cases ignore the timeout
      await this.http
        .sendRequest("http://192.168.123.32", {
          method: "get",
          responseType: "blob",
          timeout: 1,
        })
        .then((data) => {
          console.error("Success", data);
        })
        .catch((error) => {
          console.error("timeout after: ", new Date().getTime() - now, "ms", error);
        });

      console.warn("Default timout is ", this.http.getRequestTimeout());
    });




@ZweiEuro
Copy link
Author

For me this is what is printed afterwards.
2022-06-19-26

@silkimen silkimen added bug and removed bug labels Sep 16, 2022
@silkimen
Copy link
Owner

Hi @ZweiEuro, I think we forgot to update the documentation when #404 was implemented. Would you please try to set the values for connectTimeout and readTimeout in your options object instead of timeout? I guess this should fix your problem. I'd appreciate your feedback, so we can fix the documentation.

@ZweiEuro
Copy link
Author

ZweiEuro commented Sep 16, 2022

Hi @silkimen,
Currently i am doing this:

this.http.setRequestTimeout(custom_timeout ? custom_timeout : this.timeout); // This has an effect
this.http
  .sendRequest("http://" + (ip ? ip : this.device.getIP()) + ":" + this.hostPort + "/api/v1/command", {
    method: "post",
    data: body,
    timeout: this.timeout, // this has no effect
    headers: { "Content-Type": "application/json" },
    serializer: "json",
    responseType: "json",
  })

You mean i should be doing this ?

//this.http.setRequestTimeout(custom_timeout ? custom_timeout : this.timeout); // This has an effect
this.http
  .sendRequest("http://" + (ip ? ip : this.device.getIP()) + ":" + this.hostPort + "/api/v1/command", {
    method: "post",
    data: body,
    connectTimeout: this.timeout, // <------
    headers: { "Content-Type": "application/json" },
    serializer: "json",
    responseType: "json",
  })

@bluwduch
Copy link

bluwduch commented Feb 9, 2023

I had the same issue and came here to find this already reported... I tried adding additional properties to the options object connectTimeout and readTimeout and can confirm that fixed the problem.

@ZweiEuro
Copy link
Author

I think it fixed my issue as well @bluwduch I am just asking for docs and confirmation

@up2-date
Copy link

I have had the same problem, it would be nice if the documentation could be updated.

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

4 participants