java.io.InterruptedIOException: timeout
kevinkl opened this issue · comments
Hey all,
I have two activities (activity_main and activity_test) in my Android App (just a test application). Each of them has a button. If this will be clicked a login request will be sent over wasp to my server and then the other activity will be opened. When I start another app and then going back to the test App, I get this exception: java.io.InterruptedIOException: timeout after sending several requests again. If you wait about 10 seconds you can send request without the error (exception).
Here the full log, the first request is successful but the other ones throwing the InterruptedIOException:
07-07 08:14:50.129 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.129 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.133 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"tekegel@lastmail.co","password":"test12"}
07-07 08:14:50.133 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 200 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Credentials: true]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Headers: auth_token, main_category_id, Content-Type]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Methods: GET, POST, DELETE, PUT]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Origin: *]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Cache-Control: no-cache, no-transform, must-revalidate]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Connection: keep-alive]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Length: 53]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Date: Tue, 07 Jul 2015 08:14:50 GMT]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Received-Millis: 1436256890275]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Selected-Protocol: http/1.1]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Sent-Millis: 1436256890141]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Server: nginx/1.4.6 (Ubuntu)]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"auth_token":"e245bd5c-f102-4f91-8cd0-97c96c8581b7"}
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 53 bytes - Network time: 139 ms)
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Login﹕ e245bd5c-f102-4f91-8cd0-97c96c8581b7
07-07 08:14:50.345 25489-25489/com.example.root.wasptest W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"tekegel@lastmail.co","password":"test12"}
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"tekegel@lastmail.co","password":"test12"}
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- ERROR
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ Message - [java.io.InterruptedIOException: timeout]
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 0 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - no body
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 0 bytes - Network time: 5778 ms)
07-07 08:14:53.421 25489-25489/com.example.root.wasptest E/Login﹕ java.io.InterruptedIOException: timeout
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- ERROR
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ Message - [java.io.InterruptedIOException: timeout]
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 0 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - no body
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 0 bytes - Network time: 7382 ms)
Here is my source code. Did I do something wrong or is it a bug?
In the following I show just the MainActivity because the other one (TestActitvity) is exactly the same except that the MainActivity will be started.
WaspApplication.java
public class WaspApplication extends Application {
private static WaspService service;
public static WaspService getService(){
return service;
}
@Override
public void onCreate() {
super.onCreate();
service = new Wasp.Builder(this)
.setEndpoint("https://h2211501.stratoserver.net/bachelor_webservice/resources")
.setLogLevel(LogLevel.FULL)
.trustCertificates()
.build()
.create(WaspService.class);
}
}
WaspService.java
public interface WaspService {
//---Static header
@Headers("Content-Type:application/json")
@POST("/session/login")
WaspRequest login(
@Body LoginData loginData,
Callback<LoginResponse> callBack
);
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
private final RequestManager requestManager = new SimpleRequestManager();
private final WaspService service = WaspApplication.getService();
private LoginData loginData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginData = new LoginData();
loginData.setEmail("tekegel@lastmail.co");
loginData.setPassword("test12");
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WaspRequest request = service.login(loginData, callbackLogin);
requestManager.addRequest(request);
}
});
}
...
...
private final Callback<LoginResponse> callbackLogin = new Callback<LoginResponse>() {
@Override
public void onSuccess(Response response, LoginResponse loginResponse) {
Log.d("Login", loginResponse.getToken());
startTestActivity();
}
@Override
public void onError(WaspError waspError) {
Log.e("Login", waspError.getErrorMessage());
}
};
private void startTestActivity(){
startActivity(new Intent(this, TestActivity.class));
finish();
}
}
Let us check this issue
it seems it is related to retry policy. Can you change retry policy and try? Second parameter is the retry count, can you try with 0 and check the result? If you don't get the same issue, that means you can configure retry policy regarding to your needs.
RequestInterceptor interceptor = new SimpleInterceptor() {
@Override
public WaspRetryPolicy getRetryPolicy() {
return new WaspRetryPolicy(15000, 0, 1.5f);
}
}
Thanks a lot that worked! I don't get the same issue and I set the maxNumRetries
to 2 for now.
Just another thing, the README says to use the dependency compile 'com.orhanobut:wasp:1.12' is this a typo hasn't it to be compile 'com.orhanobut:wasp:1.11'?
ohh thanks, yes it's typo, fixing now :)