koush / ion

Android Asynchronous Networking and Image Loading
Other
6.29k stars 1.03k forks source link

AssertionError in AsyncSSLSocketWrapper #928

Open cirediew opened 4 years ago

cirediew commented 4 years ago

Hi!

I get the following error when running a Get using ion.

    java.lang.AssertionError
        at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:474)
        at com.koushikdutta.async.AsyncSSLSocketWrapper.handleHandshakeStatus(AsyncSSLSocketWrapper.java:378)
        at com.koushikdutta.async.AsyncSSLSocketWrapper.handshake(AsyncSSLSocketWrapper.java:182)
        at com.koushikdutta.async.http.AsyncSSLSocketMiddleware.tryHandshake(AsyncSSLSocketMiddleware.java:89)
        at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$2.onConnectCompleted(AsyncSSLSocketMiddleware.java:106)
        at com.koushikdutta.async.http.AsyncSocketMiddleware.lambda$getSocket$3$AsyncSocketMiddleware(AsyncSocketMiddleware.java:217)
        at com.koushikdutta.async.http.-$$Lambda$AsyncSocketMiddleware$glazjOxu-iNIRY4N890Wl1ngyGo.onCompleted(Unknown Source:12)
        at com.koushikdutta.async.future.SimpleFuture.lambda$setCallback$0(SimpleFuture.java:216)
        at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$h_gK5Y1XHZI1H8JTE2xOg4dXbp8.onCompleted(Unknown Source:2)
        at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
        at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:195)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:175)
        at com.koushikdutta.async.future.-$$Lambda$VNAuWcttAhMr3VsWCERbmWE6yR0.success(Unknown Source:2)
        at com.koushikdutta.async.future.SimpleFuture.lambda$success$4(SimpleFuture.java:287)
        at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$DxIsaj7NQi76eWgOKS4iviWPLV0.onCompleted(Unknown Source:4)
        at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
        at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:195)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:182)
        at com.koushikdutta.async.http.-$$Lambda$cBC5du-82c5EcL72rP5wNK7Y2Y4.onConnectCompleted(Unknown Source:2)
        at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:906)
        at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:727)
        at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:46)
        at com.koushikdutta.async.AsyncServer$8.run(AsyncServer.java:681)

It occurs here: https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java#L474

I'm not sure why or if I'm doing something wrong but using the debugger bb.remaingin and writeList.hasRemaining() are always 0 for me and therefore an assertion error is thrown.

My code:

    public static <T> Future<Response<T>> GetConnect(Context context, String url, Class<T> type, String instance, String method, API api, FutureCallback<Response<T>> callback, boolean auth) {
        String csrf_session = AccountGeneral.getInstance(context).peekAuthToken();
        if (csrf_session == null && auth) {
            LOG.CONNECTION(instance, "GETCONNECT CSRF_SESSION IS EMPTY");
            if (callback != null)
                callback.onCompleted(new AuthenticationException("Authentication required"), null);
        } else {
            //Ion ion = Ion.getDefault(context);
            Ion ion = Ion.getInstance(context, instance);
            if (LOG.ION) {
                ion.configure().setLogging(instance, Log.VERBOSE);
                LOG.CONNECTION(ion.configure().userAgent());
            }
            try {
                ion.getCookieMiddleware().clear();
            } catch (NullPointerException ignore) {
            }
            Builders.Any.B loadBuilder = ion.build(context).load(method, url);
            if (auth) {
                if (api == API.V0) {
                    LOG.CONNECTION(instance, "CSRF+SESSION: " + csrf_session);
                    loadBuilder = buildHeaders(context, loadBuilder, csrf_session);
                } else {
                    loadBuilder = buildHeadersNew(context, loadBuilder);
                }
            }
            Future<Response<T>> responseFuture = loadBuilder
                    .noCache()
                    //.proxy("192.168.109.35",8888)
                    .setTimeout(5000)
                    .followRedirect(false)
                    .as(type)
                    .withResponse();
            responseFuture.setCallback(callback);
            return responseFuture;
        }
        return null;
    }

When I'm running release mode everything seems to be working fine. So why is it not in debug mode?

Any help is appreciated!

Shvet commented 4 years ago

getting same error!! anyone found solution?

Shvet commented 4 years ago
Ion.with(context)
                .load("GET", url)
                .setTimeout(60000)
                .addHeader("device-type", "android")
                .asJsonObject().withResponse()
                .setCallback((e, result) -> {
                    Log.e("Exception", e.toString());
                    if (result != null) {
                        JsonObject object = result.getResult();
                        Log.e("Object", object.getAsString());
                    }
                });

This is what i have used

djdance commented 4 years ago

Same crash! In my case I decided to test old working app on Android 5.1 UPD on any android

djdance commented 4 years ago

I've found the solution.

in top gradle remove this 'com.android.tools.build:gradle:4.1.0-rc01

and set this 'com.android.tools.build:gradle:4.0.1'

Shvet commented 4 years ago

Worked By changing Gradle to 4.0.1

shaithana commented 4 years ago

This happens again in Gradle 4.1.0

tomeroto commented 4 years ago

I have same issues, after update my Android Studio to 4.1.

10-14 20:00:29.799 5110-5151/com.test.http E/AndroidRuntime: FATAL EXCEPTION: ion-ion
    Process: com.test.http, PID: 5110
    java.lang.AssertionError
        at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:492)
        at com.koushikdutta.async.AsyncSSLSocketWrapper.handleHandshakeStatus(AsyncSSLSocketWrapper.java:378)
        at com.koushikdutta.async.AsyncSSLSocketWrapper.handshake(AsyncSSLSocketWrapper.java:182)
        at com.koushikdutta.async.http.AsyncSSLSocketMiddleware.tryHandshake(AsyncSSLSocketMiddleware.java:89)
        at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$2.onConnectCompleted(AsyncSSLSocketMiddleware.java:106)
        at com.koushikdutta.async.http.AsyncSocketMiddleware.lambda$getSocket$3$AsyncSocketMiddleware(AsyncSocketMiddleware.java:217)
        at com.koushikdutta.async.http.-$$Lambda$AsyncSocketMiddleware$glazjOxu-iNIRY4N890Wl1ngyGo.onCompleted(lambda)
        at com.koushikdutta.async.future.SimpleFuture.lambda$setCallback$0(SimpleFuture.java:212)
        at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$h_gK5Y1XHZI1H8JTE2xOg4dXbp8.onCompleted(lambda)
        at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
        at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:191)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:174)
        at com.koushikdutta.async.future.-$$Lambda$VNAuWcttAhMr3VsWCERbmWE6yR0.success(lambda)
        at com.koushikdutta.async.future.SimpleFuture.lambda$success$4(SimpleFuture.java:279)
        at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$DxIsaj7NQi76eWgOKS4iviWPLV0.onCompleted(lambda)
        at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
        at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:191)
        at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:178)
        at com.koushikdutta.async.http.-$$Lambda$cBC5du-82c5EcL72rP5wNK7Y2Y4.onConnectCompleted(lambda)
        at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:896)
        at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:717)
        at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:46)
        at com.koushikdutta.async.AsyncServer$11.run(AsyncServer.java:671)
10-14 20:00:29.984 5110-5128/com.test.http E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f9a075e20
islamarr commented 4 years ago

The same error in Gradle 4.1.0, please Fix it

rajabpour commented 3 years ago

The same error in Gradle 4.1.1, How to fix it???

zwirne commented 3 years ago

The same error with Gradle 4.1.2.

Thx to @djdance!!! Set to 'com.android.tools.build:gradle:4.0.1' solved it

thasneemp commented 3 years ago

Hi when we can expect the fixes? koush

islamarr commented 3 years ago

Fixed in 3.1.0 implementation 'com.koushikdutta.ion:ion:3.1.0'

islamarr commented 3 years ago

The same error in Gradle 4.1.1, How to fix it???

Fixed in version 3.1.0