Flutter `SocketException: HTTP connection timed out` sometimes when app start - android

I have a Flutter application and it makes some HTTP requests to my server. However, once in a while (not sure when, but I have seen it several times a day), when I open my app, the HTTP requests that happen during the first few seconds all report the error of SocketException: HTTP connection timed out (the source code that throws this seems to be here). However, after the first few seconds, other HTTP requests will succeed.
I have tried hard reproducing it but failed. Usually this bug happens, when I put my phone there for some time and then open the app (but it is not a thing for sure; also in many cases such behavior will not trigger the bug). If the bug happens, and I close the app and reopen it immediately, it will run very well and the bug will not happen again.
I have also used Wireshark to try to look at the network packages. However, when I setup the environment as "my app (in my phone) connects to my computer with development server using wifi and http", that bug seems to never appear again. Only with the production environment "my app (in my phone) connects to a server in the cloud using https" that this bug happens. But in that case I cannot use Wireshark to look into the packages.
I know I do not provide a reproducible sample, but I really cannot find out any clues. I even cannot stably reproduce it :(
I would truly appreciate it for any suggestions!!!

I had faced this issue in one of my initial projects, which usually happens with HTTP package, I'll recommend you to try this package:
https://pub.dev/packages/dio
And if you are an android developer then you may know it is the best combination to use dio with retrofit
https://pub.dev/packages/retrofit

Related

2 Android devices blocking each others HTTP requests in same LAN

I have an Android app which is continuously downloading JSON files with status updates, and if needed it downloads corresponding zip files. What the application exactly does is irrelevant.
The problem is that if i have 2 devices running in the same LAN with the app installed, one app blocks HTTP request of the other one. So one app is running fine, the other one is constantly running into timeouts for exactly the same request (only the token in the GET parameter differs).
When i turn of the "working" device, the block is released - and the other device is running fine, without timeouts.
Myself i think it is an routing issue.
Does anybody know how to prevent this?
In my app i connect through Volley. I am using a singleton for the connection pool - build by the documentation you can find on https://developer.android.com/training/volley/requestqueue.html
This is not likely a client issue (your Android app). You should check your server implementation first.
Singleton or transient RequestQueue in Android app doesn't matter. Because number of concurrent GET requests to server depends on number of devices you have.
There seems to be an issue with android devices and timestamps that are used for the connection. I found the solution to the problem.
Search the solution in the TCP protocol / settings.

Android http connection - multiple devices cannot connect the same server

I really need help here...
I have a simple Android application that connects to my sever to fetch data over HTTPS.
Everything is working fine up until i connected to the same server from another device (iOS or Android). I am starting to get timeouts or connection refused or other errors depending on the library that I use (sometimes SSL handshake)
I tried 2 android app on the same router - fails
I tried Volley, Retrofit, plain http library - fails
if one device is connected via cellular network and one on wifi, it is working fine. However, i have seen cases that it fails even using 2 devices connected to cellular network and not wifi.
It is easy to reproduce. one app is working fine. as soon as i do an operation on the other device. the first app will not be able to connect.
iOS app using the same api/server is working fine. no failures
I ran wireshark on the android app during failure and received the following:
70 47.073286 10.0.0.1 10.0.0.138 ICMP 120 Destination unreachable (Port unreachable)
Seems like port issues. I am not sure anymore if this is a server issue or a client issue.. iOS app works fine. no issues. Only Android.
I tried:
System.setProperty("http.keepAlive", "false");
I tried setting an http header "connection :close" nothing works...
Any idea would be appreciated...
Same problem here . When my ios device connect to allstar heroes or fun run application the android device cant connect anymore . I cant find s fix for that . My router is tp link dir 615 . Maybe the problem is frpm router .
At the end of the day, it was server side issue. the IT guy gave me the following info: "incorrect flag on the tcp kernel settings" "Reuse connection" that is all I have for you. hope it can help someone else
I had the same problem. The issue seemed to be when the app tried to access ports in TIME_CLOSE here is a great explanation how this happen, changing the tcp kernel to Reuse connection, might solve the problem since the server will try to re-use those connection in TIME_CLOSE again. but it must be a solution from the client side to avoid the connection to get stuck. in my case I was trying to create connection from multiples activities and i guess they, somehow, competed for opening and closing the connections, i solved the issue using a single activity to make the connection to the server.
hope this is useful to someone.
Had exact the same issue and spent a lot of time investigating, nothing helped including "Reuse connection" flag, tried also to disable tcp_timestamp, tcp_tw_reuse, tcp_tw_recycle and enable vm safe mode for the app as suggested here:
https://github.com/square/okhttp/issues/903
https://github.com/square/okhttp/issues/1037
https://github.com/square/okhttp/issues/1518
but all in vein.
Further more, the very strange thing was that I had two different instances/servers which I made exactly the same in order to track down the issue and one server didn't have any issues.
So in the end:
Instance reboot solved problem with connections.
(or just need to restart networking service)
(c) My server/instance admin

PhoneGap: some AJAX POSTs are never sent

My PhoneGap app is built with jQuery mobile and currently I'm testing on Android. Cross domain parameters in jqm are set and I use a wildcard for the phonegap "access"-origins. The app uses AJAX for some JSON-communication. Now all ajax GETs seem to work without a problem, but about 40% of the POSTs never reach my server (i.e. not even headers, logs show no signs of those posts). All the posts are very basic ajax calls to exactly the same address, with some minimal json-load, like an id and some short value. I am using the Chrome device inspect and can confirm the posts are looking consistent, but about 40% of those posts keep the status "pending" and will eventually timeout.
I've read something about caching, post-data is always unique, but I've added nocache-headers to the servers responses. Posts should never be cached imo, but this didn't help me anyway.
The bare jqm-app works fine in the browser. Embedded in phonegap, some posts fail.. does anybody have a clue?
Try adding these options to your jQuery.ajax calls
dataType: 'jsonp',
cache: false
The first one allows cross domain posts and the second ensures that each request receives a unique parameter circumventing browser-side caching
Ok, I've set up a second test project with only the functionality of sending ajax requests, both post and get, on short intervals (like 2s). Turned out that gets where getting timed out too and after a few iterations, everything just timed out.
Lately I've been experiencing Chrome-crashes while developing, so I set up my server to do some well-arranged logging. I didn't start the app from Eclipse this time, but disconnected my phone and started it manually on the phone itself. Guess what: everything just works fine, all ajax requests arrive at the server.
I had already tested without the Chrome DevTools device inspect, but with the phone connected to usb: didn't help. But Chrome crashing quite frequently still makes me suspect it has something to do with it while connected to the pc.
Update:
I ran into problems again when sending some larger requests, like images in base64. Now I set header "Connection: close" on my server and things seem smooth again, even with Chrome DevTools inspect, except for the crashing of Chrome.

Why do i get time out in bluemix sample app?

I have followed the tutorial of bluemix that is called bluelist. See here: http://www.ibm.com/developerworks/library/mo-android-mobiledata-app/#N1021F
I have installed all required libs and i have installed everything in the bluemix side.
I get error IBMBLUEMIX-0554E: timeout expired before connection could be established.
any solutions?
This could be caused by a couple issues.
You could be attempting to access an internal test zone (AKA stage1) without being in the internal network. Make sure there is not stage1 present in your app route.
Your phone/emulator may not be connected to a network properly. Please be sure that your test device is connected to the internet via data service or local connection. You can try running a speed test on that device if in doubt. Some custom created emulators can also have issues of their own. Try using a physical device if possible.
You may be on a network using a proxy server. I have heard of timeout issues when using a proxy. You may need to use a network that does not utilize a proxy.
This issue comes intermittently some times due to network/connectivity issue.Also you need to Verify that your applicationId, applicationSecret, and applicationRoute are correct.You can go to the Overview of your Mobile Cloud Service application on ACE to find your applicationId and Route. The applicationSecret is on the MAS portion of the ACE UI for your application.
Similar issue was reported already:
https://developer.ibm.com/answers/questions/26821/getting-time-out-error-while-conencting-to-mobile-cloud-bluemix-application.html

Android emulator loses internet connection after a period of time (inactive or active)

I know that many people asked this before I do, but I can't find any answer so got to repost it here.
So when I start the android emulator, everything is fine. But after a while, like 5 minutes, then it'll lose the internet connection, which means I can't access to the internet via browser, or my app. The only thing I can do is to restart the emulator by close it and start it again.
Any response is appreciated.
This is due to a bug in the emulator code. Basically it doesn't close UDP sockets which in turn causes "socket leak". If you monitor socket connections for the emulator-x86.exe process on your host (Winows), you will notice that the number of connections keep going up as you visit new sites on a browser for example. When the count goes beyond a point (around 100), the emulator fails to open new network connections. I have the same issue and did not find any solution so far.
I've had success using emulators that don't have the Google APIs, so maybe there is something in the pre-loaded Google API junk that is calling home using UDP sockets like #user3361886 described.
Unfortunately they have not provide an image without Google APIs for the latest (API 25). So do as much testing as possible using older versions without Google APIs, and then just test with Google APIs when you specifically need to test Google play services and/or verify your app works properly in API 25 or higher.
Try with Network type > Full and Signal Strength > Great
It worked for me

Categories

Resources