capacitor-community / http

Community plugin for native HTTP
MIT License
208 stars 135 forks source link

Inconsistent timeout behavior makes this plugin unusable #230

Open funkyvisions opened 2 years ago

funkyvisions commented 2 years ago

Describe the bug The timeout functionality on this plugin is inconsistent across browser, iOS, and Android making it unusable for my project. I previously used cordova-advanced-http on Cordova and it worked really well. This is not a good replacement.

To Reproduce Steps to reproduce the behavior: Download my project at https://github.com/funkyvisions/capacitor-demo

Expected behavior Run the project. It will call 3 different endpoints with a read and connection timeout of 10 seconds.

  1. https://httpstat.us/200?sleep=1000
  2. https://httpstat.us/200?sleep=15000
  3. https://thisendpointdoesnotexist.com

On the browser:

  1. Works fine. Gets 200 response.
  2. Doesn't timeout after 10 seconds like it should. Returns response after 15 seconds.
  3. Gets an error like it should.

On iOS:

  1. Works fine. Gets 200 response.
  2. Never returns.
  3. Never returns.

On Android:

  1. Works fine. Gets 200 response.
  2. Works fine. Times out after 10 seconds.
  3. Gets an error like it should.

Additional context This is the code in question:

    async function callHttp(url) {
      alert(`Calling ${url}`)
      let response
      try {
        response = await Http.get({
          url: url,
          connectTimeout: 10000,
          readTimeout: 10000
        })
      } catch(e) {
        response = {
          message: e.message
        }
      }
      alert(JSON.stringify(response))
    }

    await callHttp('https://httpstat.us/200?sleep=1000')
    await callHttp('https://httpstat.us/200?sleep=15000')
    await callHttp('https://thisendpointdoesnotexist.com')
funkyvisions commented 2 years ago

I did figure out how to get cordova-advanced-http to work, so that may be my backup plan until this plugin works a little better.

funkyvisions commented 2 years ago

Sweet. It looks like https://github.com/capacitor-community/http/issues/224 handles the iOS timeout and unknown endpoint issues. So now I just need to get timeout to work on browser (not as critical).