SkygearIO / skygear-SDK-Android

Skygear Android SDK
Other
12 stars 36 forks source link

Unable to complete Sign Up/In procedure, due to request timeouted #18

Closed heapwalker closed 8 years ago

heapwalker commented 8 years ago

At Sign Up procedure, SDK invoked onAuthFail callback while a user record is created on server DB. From logcat, such error message appears after android fire a web service request:

06-29 17:22:56.714 11386-11386/io.skygear.skygear_example I/dalvikvm: DexOpt: illegal method access (call Lcom/android/volley/Request;.finish (Ljava/lang/String;)V from Lio/skygear/skygear/RequestManager$JsonRequest;)
06-29 17:22:56.714 11386-11386/io.skygear.skygear_example I/dalvikvm: Could not find method com.android.volley.Request.finish, referenced from method io.skygear.skygear.RequestManager$JsonRequest.access$super

Steps to reproduce:

  1. Clone this repo and open the project using Android Studio
  2. At io.skygear.skygear_example.MyApplication, specify the correct Endpoint and API Key.
  3. Build and launch the app into an android phone
  4. On the phone, click into SignupActivity, fill the username and password.
  5. After a while, the above error messages appear (at logcat console) and the app displayed a dialog, with message (tracing the code reveal that the dialog is displayed from SignupActivity#doSignup, at the onAuthFail callback):
Signup failed
Fail with reason
null

Server DB Data

However, when I log into server's postgresql, I see that the user record with my username was created. I am not sure whether the SDK really faced some (network) error

Control Trial

The same outcome would occur even I created a new Android Studio project and import the SDK via gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'

    compile 'io.skygear:skygear:0.0.1'
}
heapwalker commented 8 years ago

Btw, here is the server log I captured from Skygear Developer Portal after a test case I made, with some private info replaced with *****

2016-06-29 18:03:46 X-Forwarded-Port: [80]
2016-06-29 18:03:46 X-Skygear-Api-Key: [*****]
2016-06-29 18:03:46 Opening DBConn: {pq skygearprototype postgresql://*****:*****@*****}
2016-06-29 18:03:46 {\"action\":\"auth:signup\",\"username\":\"ryanpang3\",\"email\":null,\"password\":\"*****\",\"api_key\":\"*****\"}
2016-06-29 18:03:46 Connection: [close]
2016-06-29 18:03:46 Content-Type: [application/json]
2016-06-29 18:03:46 User-Agent: [Dalvik/1.6.0 (Linux; U; Android 4.3; C5303 Build/12.1.A.1.207)]
2016-06-29 18:03:46 Accept-Encoding: [gzip]
2016-06-29 18:03:46 POST /auth/signup
2016-06-29 18:03:46 ------ Request: ------
2016-06-29 18:03:46 X-Forwarded-For: [172.20.44.35]
2016-06-29 18:03:46 ------ Header: ------
2016-06-29 18:03:46 Get DB OK
2016-06-29 18:03:46 X-Forwarded-Proto: [http]
2016-06-29 18:03:46 Content-Length: [127]
2016-06-29 18:03:49 Opening DBConn: {pq skygearprototype postgresql://*****:*****@*****}
2016-06-29 18:03:49 X-Skygear-Api-Key: [*****]
2016-06-29 18:03:49 Connection: [close]
2016-06-29 18:03:49 Get DB OK
2016-06-29 18:03:49 User-Agent: [Dalvik/1.6.0 (Linux; U; Android 4.3; C5303 Build/12.1.A.1.207)]
2016-06-29 18:03:49 Content-Length: [127]
2016-06-29 18:03:49 Accept-Encoding: [gzip]
2016-06-29 18:03:49 Content-Type: [application/json]
2016-06-29 18:03:49 POST /auth/signup
2016-06-29 18:03:49 ------ Request: ------
2016-06-29 18:03:49 X-Forwarded-For: [10.2.4.0]
2016-06-29 18:03:49 ------ Header: ------
2016-06-29 18:03:49 {\"action\":\"auth:signup\",\"username\":\"ryanpang3\",\"email\":null,\"password\":\"*****\",\"api_key\":\"*****\"}
2016-06-29 18:03:49 X-Forwarded-Proto: [http]
2016-06-29 18:03:49 X-Forwarded-Port: [80]
rickmak commented 8 years ago

@cpryanpang Do you think it is related to auth provider? I remember skygearprototype is using facebook auth provider.

heapwalker commented 8 years ago

@rickmak How do I determine? What/Where should I check?

rickmak commented 8 years ago

I I think @cpandrewchung or @cpdavidng can advise on the where is the repos hosted? Since you are using https://skygearprototype.staging.skygeario.com/

heapwalker commented 8 years ago

I have figured out the reason: the web service request elapsed too long and Android Volley library timeout-ed the request. That's why, as described above, on server side an user record with my username was created, but on client side the app failed to receive anything

FYR, below is how I figured out the reason:

//  class io.skygear.skygear.Request
    @Override
    public void onErrorResponse(VolleyError error) {
+      Log.d("Request", "#onErrorResponse " + error.toString());
       // ...
    }

The logcat output:

07-05 12:50:41.582 30644-30644/io.skygear.skygear_example D/Request: #onErrorResponse com.android.volley.TimeoutError

The default timeout limit is 2.5 second (com.android.volley.DefaultRetryPolicy.DEFAULT_TIMEOUT_MS) Following http://stackoverflow.com/questions/17094718/change-volley-timeout-duration , below is my quick tuning to enlarge the timeout limit and prove the timeout is really the key reason:

//  class io.skygear.skygear.RequestManager
    public void sendRequest(final Request request) {
        // ...
        JsonObjectRequest jsonRequest = new JsonRequest(
                url,
                new JSONObject(data),
                this.getExtraHeaders(),
                request,
                request
        );

+       jsonRequest.setRetryPolicy(new DefaultRetryPolicy(
+           10 * 1000,
+           DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
+           DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
+       ));
        // ...
    }

I think It would be good if the SDK provide some setter functions to allows us adjust such timeout (and possibly the retry count)?

rickmak commented 8 years ago

Let add a standard way to set the time out in coming release first. For retry, I think it will better to handle by application code? I believe the application will want to prompt for user that the internet have some problem and we are retrying.

heapwalker commented 8 years ago

Right, I go along with you. Thx :)