2

I created about 40 requests with okhttp(2.5.0) to access internet at one time in every 45 sec(just for testing). All was fine when phone was working, but if the phone stayed in standby state, the following exception would occur,

10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err: java.net.ConnectException: failed to connect to api.thinkpage.cn/115.29.232.24 (port 443) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at libcore.io.IoBridge.isConnected(IoBridge.java:238)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at libcore.io.IoBridge.connectErrno(IoBridge.java:171)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at libcore.io.IoBridge.connect(IoBridge.java:122)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:456)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.net.Socket.connect(Socket.java:882)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.internal.Platform$Android.connectSocket(Platform.java:190)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Connection.connectSocket(Connection.java:196)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Connection.connect(Connection.java:172)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:367)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:245)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Call.getResponse(Call.java:267)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Call.access$100(Call.java:34)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at java.lang.Thread.run(Thread.java:818)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err: Caused by: android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)
10-29 01:31:46.563 15846-22190/com.example.weathertrack W/System.err:     at libcore.io.IoBridge.isConnected(IoBridge.java:223)

I tested several time, I found if my app is in foreground, 40 requests work fine in every round; even my app was in backgroud, but as long as phone was not in standby state, it also seemed worked OK. But ConnectException would happen after few successful access round. And in these test process, i had set okhttpclient's maximum number of concurrent to ONE.

I also found a old question here.

Creating new socket after closing an old one causes connection refused

So did android system limit concurrently network access in one app in standby state?

ADD1

now, I can basically affirmed that this problem caused by miui rom. other guy tested it with other rom, and such problem never happened. it seems I should apologize to google engineer for blaming them wrong lol.

Community
  • 1
  • 1

0 Answers0