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

Cancel not freeing sockets #374

Open
nschwermann opened this issue Sep 29, 2014 · 1 comment
Open

Cancel not freeing sockets #374

nschwermann opened this issue Sep 29, 2014 · 1 comment
Labels

Comments

@nschwermann
Copy link

I have limited the number of sockets in the socket middleware but I find that when I cancel a request the socket is not released. Here is an example with output.

What I would expect here is for the first 3 requests to be canceled and the 4th request to print the html for google.com

What is happening, I get a callback for the 3 cancel calls. However there is still no socket available for the final request and it eventually times out. ION then later prints a timeout exception for each socket that had been cancelled. Now any future requests to google.com will timeout on this ion instance. However requests to other domains work.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);
        Ion ion = Ion.getInstance(this, "test");
        ion.configure().setLogging("test", Log.VERBOSE);
        ion.getHttpClient().getSocketMiddleware().setMaxConnectionCount(2);
        ion.getHttpClient().getSocketMiddleware().setConnectAllAddresses(false);
        ion.build(this).load("http://google.com").group(this).asString().setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                printInfo(e, result);
            }
        });
        ion.cancelAll(this);
        ion.build(this).load("http://google.com").group(this).asString().setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                printInfo(e, result);
            }
        });
        ion.cancelAll(this);
        ion.build(this).load("http://google.com").group(this).asString().setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                printInfo(e, result);
            }
        });
        ion.cancelAll(this);
        ion.build(this).load("http://google.com").group(this).asString().setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {
                printInfo(e, result);
            }
        });

    }

    void printInfo(Exception e, String result){
        if(e != null) {
            Log.e("test", e);
        } else {
            Log.d("test", result);
        }
    }
 32697                   test  D  (0 ms) http://google.com: preparing request
 32697                   test  I  (0 ms) http://google.com: Using loader: com.koushikdutta.ion.loader.HttpLoader@4343d608
 32697                   test  D  (0 ms) http://google.com: Executing request.
 32697           starshoptest  E  null
 32697           starshoptest  E  java.util.concurrent.CancellationException
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancelInternal(SimpleFuture.java:39)
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancel(SimpleFuture.java:54)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:348)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:387)
 32697           starshoptest  E    at com.pinsightmedia.starshop.ui.AboutActivity.onCreate(AboutActivity.java:27)
 32697           starshoptest  E    at android.app.Activity.performCreate(Activity.java:5451)
 32697           starshoptest  E    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
 32697           starshoptest  E    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
 32697           starshoptest  E    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
 32697           starshoptest  E    at android.app.ActivityThread.access$900(ActivityThread.java:173)
 32697           starshoptest  E    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 32697           starshoptest  E    at android.os.Handler.dispatchMessage(Handler.java:102)
 32697           starshoptest  E    at android.os.Looper.loop(Looper.java:136)
 32697           starshoptest  E    at android.app.ActivityThread.main(ActivityThread.java:5579)
 32697           starshoptest  E    at java.lang.reflect.Method.invokeNative(Native Method)
 32697           starshoptest  E    at java.lang.reflect.Method.invoke(Method.java:515)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
 32697           starshoptest  E    at dalvik.system.NativeStart.main(Native Method)
 32697                   test  D  (0 ms) http://google.com: preparing request
 32697                   test  I  (0 ms) http://google.com: Using loader: com.koushikdutta.ion.loader.HttpLoader@4343d608
 32697           starshoptest  E  null
 32697           starshoptest  E  java.util.concurrent.CancellationException
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancelInternal(SimpleFuture.java:39)
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancel(SimpleFuture.java:54)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:348)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:387)
 32697           starshoptest  E    at com.pinsightmedia.starshop.ui.AboutActivity.onCreate(AboutActivity.java:34)
 32697           starshoptest  E    at android.app.Activity.performCreate(Activity.java:5451)
 32697           starshoptest  E    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
 32697           starshoptest  E    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
 32697           starshoptest  E    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
 32697           starshoptest  E    at android.app.ActivityThread.access$900(ActivityThread.java:173)
 32697           starshoptest  E    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 32697           starshoptest  E    at android.os.Handler.dispatchMessage(Handler.java:102)
 32697           starshoptest  E    at android.os.Looper.loop(Looper.java:136)
 32697           starshoptest  E    at android.app.ActivityThread.main(ActivityThread.java:5579)
 32697           starshoptest  E    at java.lang.reflect.Method.invokeNative(Native Method)
 32697           starshoptest  E    at java.lang.reflect.Method.invoke(Method.java:515)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
 32697           starshoptest  E    at dalvik.system.NativeStart.main(Native Method)
 32697                   test  D  (0 ms) http://google.com: preparing request
 32697                   test  I  (0 ms) http://google.com: Using loader: com.koushikdutta.ion.loader.HttpLoader@4343d608
 32697           starshoptest  E  null
 32697           starshoptest  E  java.util.concurrent.CancellationException
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancelInternal(SimpleFuture.java:39)
 32697           starshoptest  E    at com.koushikdutta.async.future.SimpleFuture.cancel(SimpleFuture.java:54)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:348)
 32697           starshoptest  E    at com.koushikdutta.ion.Ion.cancelAll(Ion.java:387)
 32697           starshoptest  E    at com.pinsightmedia.starshop.ui.AboutActivity.onCreate(AboutActivity.java:41)
 32697           starshoptest  E    at android.app.Activity.performCreate(Activity.java:5451)
 32697           starshoptest  E    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
 32697           starshoptest  E    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2359)
 32697           starshoptest  E    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2453)
 32697           starshoptest  E    at android.app.ActivityThread.access$900(ActivityThread.java:173)
 32697           starshoptest  E    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
 32697           starshoptest  E    at android.os.Handler.dispatchMessage(Handler.java:102)
 32697           starshoptest  E    at android.os.Looper.loop(Looper.java:136)
 32697           starshoptest  E    at android.app.ActivityThread.main(ActivityThread.java:5579)
 32697           starshoptest  E    at java.lang.reflect.Method.invokeNative(Native Method)
 32697           starshoptest  E    at java.lang.reflect.Method.invoke(Method.java:515)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
 32697           starshoptest  E    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
 32697           starshoptest  E    at dalvik.system.NativeStart.main(Native Method)
 32697                   test  D  (0 ms) http://google.com: preparing request
 32697                   test  I  (0 ms) http://google.com: Using loader: com.koushikdutta.ion.loader.HttpLoader@4343d608
 32697                   test  D  (40 ms) http://google.com: Connecting socket
 32697                   test  D  (0 ms) http://google.com: Executing request.
 32697                   test  D  (3 ms) http://google.com: Connecting socket
 32697                   test  D  (0 ms) http://google.com: Executing request.
 32697                   test  D  (0 ms) http://google.com: Executing request.
 32697                   test  V  (61 ms) http://google.com: socket connected
 32697                   test  V  (26 ms) http://google.com: socket connected
 32697                   test  E  (30029 ms) http://google.com: Connection error
 32697                   test  E  null
 32697                   test  E  java.util.concurrent.TimeoutException
 32697                   test  E    at com.koushikdutta.async.http.AsyncHttpClient$2.run(AsyncHttpClient.java:240)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:683)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:700)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:608)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:37)
 32697                   test  E    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:557)
 32697                   test  E  (30003 ms) http://google.com: Connection error
 32697                   test  E  null
 32697                   test  E  java.util.concurrent.TimeoutException
 32697                   test  E    at com.koushikdutta.async.http.AsyncHttpClient$2.run(AsyncHttpClient.java:240)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:683)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:700)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:608)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:37)
 32697                   test  E    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:557)
 32697                   test  E  (30005 ms) http://google.com: Connection error
 32697                   test  E  null
 32697                   test  E  java.util.concurrent.TimeoutException
 32697                   test  E    at com.koushikdutta.async.http.AsyncHttpClient$2.run(AsyncHttpClient.java:240)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:683)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:700)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:608)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:37)
 32697                   test  E    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:557)
 32697                   test  E  (30009 ms) http://google.com: Connection error
 32697                   test  E  null
 32697                   test  E  java.util.concurrent.TimeoutException
 32697                   test  E    at com.koushikdutta.async.http.AsyncHttpClient$2.run(AsyncHttpClient.java:240)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:683)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:700)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:608)
 32697                   test  E    at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:37)
 32697                   test  E    at com.koushikdutta.async.AsyncServer$13.run(AsyncServer.java:557)
 32697                   test  D  (30013 ms) http://google.com: context has died: Activity finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants