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

Exception com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.net.SocketTimeoutException #125

Closed
sm-tester opened this issue May 26, 2017 · 13 comments

Comments

@sm-tester
Copy link

Hi, I know maybe will be slowly my internet speed, I know maybe requests will be timeout, but why crash?

library not called to onError callback, crash when doing request:
Caused by java.net.SocketTimeoutException: java.net.PlainSocketImpl.read (PlainSocketImpl.java:488) java.net.PlainSocketImpl.access$000 (PlainSocketImpl.java:37) java.net.PlainSocketImpl$PlainSocketInputStream.read (PlainSocketImpl.java:237) okio.Okio$2.read (Okio.java:138) okio.AsyncTimeout$2.read (AsyncTimeout.java:236) okio.RealBufferedSource.indexOf (RealBufferedSource.java:325) okio.RealBufferedSource.indexOf (RealBufferedSource.java:314) okio.RealBufferedSource.readUtf8LineStrict (RealBufferedSource.java:210) okhttp3.internal.http1.Http1Codec.readResponseHeaders (Http1Codec.java:189) okhttp3.internal.http.CallServerInterceptor.intercept (CallServerInterceptor.java:67) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java:45) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67) okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java:93) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67) okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java:93) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept (RetryAndFollowUpInterceptor.java:120) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67) com.androidnetworking.interceptors.HttpLoggingInterceptor.intercept (HttpLoggingInterceptor.java:221) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:92) okhttp3.internal.http.RealInterceptorChain.proceed (RealInterceptorChain.java:67) okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java:179) okhttp3.RealCall.execute (RealCall.java:63) com.androidnetworking.internal.InternalNetworking.performSimpleRequest (InternalNetworking.java:112) com.androidnetworking.internal.InternalRunnable.executeSimpleRequest (InternalRunnable.java:68) com.androidnetworking.internal.InternalRunnable.run (InternalRunnable.java:54) java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:422) java.util.concurrent.FutureTask.run (FutureTask.java:237) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587) com.androidnetworking.core.PriorityThreadFactory$1.run (PriorityThreadFactory.java:47) java.lang.Thread.run (Thread.java:818)

Anybody know how to fix it?

@amitshekhariitbhu
Copy link
Owner

@Boyfox can u tell me more about the request like url, method and request parameters.

@sm-tester
Copy link
Author

Hi @amitshekhariitbhu , i can't found what is page who called to api, but my i can pass here my style using AndroidFastNetworking library, for example post request:
`try {
JSONObject addComReqJS = new JSONObject();
addComReqJS.put("teamId", team.get("id").getAsInt());
addComReqJS.put("text", new String(teamCommentET.getText().toString()).getBytes("UTF-8"));
AndroidNetworking.post(FussballApp.SERVER_URL + "gameservice/teams/comments/add")
.addQueryParameter("token", URLDecoder.decode(UserSettings.object().getToken(), "utf-8"))
.addJSONObjectBody(addComReqJS)
.setExecutor(Executors.newSingleThreadExecutor())
.setPriority(Priority.MEDIUM)
.setTag("addComment")
.build()
.getAsParsed(new TypeToken() {
}, new ParsedRequestListener() {
@OverRide
public void onResponse(Object response) {
final TeamComment newComment = (TeamComment) response;
FussballApp.runOnUIThread(new Runnable() {
@OverRide
public void run() {
Utilities.hideKeyboard(teamCommentET);
teamCommentET.setText("");
mComsAdapter.addNewItem(newComment);
}
});
}

                @Override
                public void onError(ANError anError) {
                    HLog.i("GAMEDET", "Error : " + anError.toString());
                }
            });
    } catch (Exception e) {
        e.printStackTrace();
    }`

I always get response on the separately thread -> setExecutor(Executors.newSingleThreadExecutor())

@sm-tester
Copy link
Author

And there are screenshots from firebase crash report:
screen shot 2017-05-26 at 1 04 24 pm
screen shot 2017-05-26 at 1 04 40 pm
screen shot 2017-05-26 at 1 04 52 pm

@sm-tester
Copy link
Author

sm-tester commented May 26, 2017

Maybe simply need add try catch to executeSimpleRequest method in the InternalRunnable class of FAN(Fast Android Networking) library? and then in the catch will call to onError callback about timeout exception to Target

@kn9636
Copy link

kn9636 commented Sep 1, 2018

My error is androidnetworking error ANerror only yahi likha aa raha he

@amitshekhariitbhu
Copy link
Owner

@kn9636 try increasing the timeout?

@kn9636
Copy link

kn9636 commented Sep 1, 2018

Sir again error is coming

@kn9636
Copy link

kn9636 commented Sep 1, 2018

Sir how to solve this problem

@kn9636
Copy link

kn9636 commented Sep 1, 2018

how to solve this error "com.androidnetworking.error.ANError"

@hasnain-ahmad
Copy link

@kn9636 Did you find the solution? @amitshekhariitbhu where to increase the timeout in app code or web APIs code..?

@Vishal6ji2
Copy link

com.androidnetworking.error.ANError: com.androidnetworking.error.ANError: java.net.SocketTimeoutException: timeout

I have this error today but yesterday there is no such type error and also i don't check anything yesterday or today . this error is come today but yesterday there is no error

@Vishal6ji2
Copy link

Please help me for this kind of error .Is there is a server side probelm ?

@hasnain-ahmad
Copy link

hasnain-ahmad commented Nov 4, 2019

@kn9636 Did you find the solution? @amitshekhariitbhu where to increase the timeout in app code or web APIs code..?

Here i have increase the connectTimeout in minutes.

GsonBuilder builder;
Gson gson;
builder = new GsonBuilder();
builder.excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC); builder.excludeFieldsWithoutExposeAnnotation();
builder.serializeNulls();
gson = builder.create();

OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(5, TimeUnit.MINUTES)
                .readTimeout(5, TimeUnit.MINUTES)
                .writeTimeout(5, TimeUnit.MINUTES)
                .build();

AndroidNetworking.initialize(getApplicationContext(), okHttpClient);
AndroidNetworking.setParserFactory(new GsonParserFactory(gson));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants