Android Google Endpoints SocketTimeoutException at NativeCrypto.SSL_Read

49 views
Skip to first unread message

Cbsch via StackOverflow

unread,
Nov 3, 2014, 12:37:29 PM11/3/14
to google-appengin...@googlegroups.com

I recently started having this error on several different endpoint methods on Android communicating with Google App Engine through Google endpoints.

It seems to happen somewhat randomly, but usually more often on the first call to the method after a new application start, if I cause the operation to execute again it usually works, but after doing that a few more times it can start to fail again.

I have tried this on both a wifi connection and 3g connection, and it happens during both of them.

The logs in App Engine indicates the operation succeeded at about 100ms elapsed.

Any ideas what might be causing this and / or how to fix it?

(This particular method is called after a successful login with Facebook and registers the user on the GAE backend server, but it seems to happen to many unrelated methods.)

11-03 18:20:45.995: E/UserController(5798): logInFacebook
11-03 18:20:45.995: E/UserController(5798): java.net.SocketTimeoutException: Read timed out 
11-03 18:20:45.995: E/UserController(5798):         at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_read(Native Method)
11-03 18:20:45.995: E/UserController(5798):         at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:665)
11-03 18:20:45.995: E/UserController(5798):         at libcore.io.Streams.readSingleByte(Streams.java:41)
11-03 18:20:45.995: E/UserController(5798):         at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.read(OpenSSLSocketImpl.java:649)
11-03 18:20:45.995: E/UserController(5798):         at libcore.io.Streams.readAsciiLine(Streams.java:201)
11-03 18:20:45.995: E/UserController(5798):         at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:573)
11-03 18:20:45.995: E/UserController(5798):         at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:821)
11-03 18:20:45.995: E/UserController(5798):         at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:283)
11-03 18:20:45.995: E/UserController(5798):         at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:495)
11-03 18:20:45.995: E/UserController(5798):         at libcore.net.http.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:134)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.http.javanet.NetHttpResponse.<init>(NetHttpResponse.java:36)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:94)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:965)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:410)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
11-03 18:20:45.995: E/UserController(5798):         at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
11-03 18:20:45.995: E/UserController(5798):         at com.example.app.model.User.logInFacebook(User.java:73)
11-03 18:20:45.995: E/UserController(5798):         at com.example.app.controller.UserController$2.doInBackground(UserController.java:100)
11-03 18:20:45.995: E/UserController(5798):         at com.example.app.controller.UserController$2.doInBackground(UserController.java:1)
11-03 18:20:45.995: E/UserController(5798):         at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-03 18:20:45.995: E/UserController(5798):         at java.util.concurrent.FutureTask.run(FutureTask.java:234)
11-03 18:20:45.995: E/UserController(5798):         at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
11-03 18:20:45.995: E/UserController(5798):         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
11-03 18:20:45.995: E/UserController(5798):         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
11-03 18:20:45.995: E/UserController(5798):         at java.lang.Thread.run(Thread.java:864)


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/26719706/android-google-endpoints-sockettimeoutexception-at-nativecrypto-ssl-read

Cbsch via StackOverflow

unread,
Nov 3, 2014, 2:32:32 PM11/3/14
to google-appengin...@googlegroups.com

I finally found an answer for this. I struggled with this for over a week before posting the question, but only hours after posting I figured it out myself.

The reason I got the error was because I initialized the endpoint incorrectly.

Some of my methods on this endpoint I knew would take a long time to execute, so I made my own HttpRequestInitializer which would set the read timeout like this.

Userendpoint getUserEndpoint(final Integer timeout) {
        Userendpoint.Builder builder = new Userendpoint.Builder(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                new HttpRequestInitializer() {
                    public void initialize(HttpRequest httpRequest) {
                        httpRequest.setReadTimeout(DEFAULT_TIMEOUT_SECONDS * 1000);
                        if (timeout != null) {      
                            httpRequest.setReadTimeout(timeout * 1000);
                        }                           
                    }                       
                });                 

        builder.setRootUrl(ROOT_URL);
        builder = CloudEndpointUtils.updateBuilder(builder);
        Userendpoint endpoint = builder.build();
        return endpoint;
    }

The way I ended up fixing it is equivalent to this:

Userendpoint getUserEndpoint() {
        Userendpoint.Builder builder = new Userendpoint.Builder(
                AndroidHttp.newCompatibleTransport(), new JacksonFactory(),
                new HttpRequestInitializer() {
                    public void initialize(HttpRequest httpRequest) {
                        httpRequest.setConnectTimeout(0);
                        httpRequest.setReadTimeout(0);                      
                    }                       
                });                 

        builder.setRootUrl(ROOT_URL);
        builder = CloudEndpointUtils.updateBuilder(builder);
        Userendpoint endpoint = builder.build();
        return endpoint;
    }

This basically disables timeout on connects and reads. This is probably not a good way to solve it, but if anyone else has had the same problem this may lead you to a good solution. Another way to solve it is simply passing in null as the HttpRequestInitializer, but for now I want to experiment with it.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/26719706/android-google-endpoints-sockettimeoutexception-at-nativecrypto-ssl-read/26721602#26721602
Reply all
Reply to author
Forward
0 new messages