Long pending request in Android Emulator

I’m using Angular http and sending a request to a local URL which should be checked whether it returns a response or not ( - does not exist).

I expect an error since this doesn’t exist. The request is pending in the browser for about 20 seconds, I think it is ok. But in my Android Emulator from Android Studio, the request hangs for over 2 minutes until I then get an error.

Why is this taking so long, I analyzed it with chrome:inspect but I can’t figure it out.

I’ve already spent a lot of time on it. Can someone please help me here. Thank you.

I’m using Emulator version 32.1.11-9536276. I also set network type from 3G to 4G. Nothing fixed it.

@capacitor/android": “5.5.1”,
@ionic/angular": “6.7.5”,

Is there someone who can help me, please?

You need to provide more details.

  • What error are you getting? Just a 404 from the response?
  • What does the network request look like in DevTools?
  • Are you using CapacitorHttp or just standard JS to make your API calls?

Thank you for your help.

I am using the Angular httpClient from @angular/common/http because I want to convert an Angular project into a simple app. I need to request a URL to check if it is online, hence the API endpoint /onlinestate . However, I only receive a net: ERR_CONNECTION_TIMED_OUT error after 2.2 minutes. When I run the application in the browser, it only takes about 20 seconds.

I have another question; if I use HTTPS, does the server need a specific SSL certificate? Or what requirements do I need? I’m quite new to this area, please excuse my lack of knowledge.

Thank you.

This is because your physical device doesn’t have access to which I am assuming is your own computer. On that computer, you’ll need to open up port 8081 in the firewall. For my local development, I only allow my Android device’s IP to connect to my computer running my dev API. It’s a little more secure.

In regards to HTTPS, you are probably using a a self-signed cert right now which is fine for local development. I don’t mess with HTTPS in my dev env so I don’t know if Android will have issues with it being self-signed or not.

For production, you will definitely want a trusted SSL cert. Many providers now integrate with letsencrypt.org which provides free certs. Or if you are using AWS, they provide their own SSL certificate service. The other big players probably also provide their own services (Google, Azure, etc.).

Thank you for your response. However, I believe there might be a misunderstanding. In my application, it is possible to configure multiple API servers. I make requests to these API servers, but only if they are online. It is not mandatory for a correct API server to be configured. In my example, for instance, the specified IP address does not even exist. Therefore, the request should fail. The issue is that the request is pending for almost 2 minutes before I receive an error.

That’s an interesting API design. I am not familiar with Angular, but with some quick Googling, it appears the default timeout for @angular/common/http is two minutes and there is no way to override this atm as there is still an open issue for it - The possibility of setting Timeouts with HttpClient · Issue #34421 · angular/angular · GitHub.

So, you either need to do some searching to see if you can “hack” it to force a custom timeout or use a different library. I personally use Axios which does provide a timeout option. Or use XMLHttpRequest directly which also provides a timeout option.

This why I posted the link to help you understand how to ask questions.If you would’ve posted this info, along with some code and the things you have tried, you would have already had the answer.


Thank you anyway, I will do better next time.

1 Like