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

Subscription crashing application due to "java.util.NoSuchElementException" exception #114

Closed
SahajRana opened this issue Feb 9, 2019 · 14 comments
Assignees
Labels
bug Something isn't working pending-response Issue is pending response from the issue requestor

Comments

@SahajRana
Copy link

Describe the bug
Subscription crashing application due to "AppSyncSubscriptionCall$Callback.onCompleted()" on a null object reference, after some time of using subscription on cancel.

Error


02-09 12:22:37.718 5278-5964/com.rana.sahaj.myyu E/AndroidRuntime: FATAL EXCEPTION: Thread-90
    Process: com.rana.sahaj.myyu, PID: 5278
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall$Callback.onCompleted()' on a null object reference
        at com.apollographql.apollo.internal.RealAppSyncSubscriptionCall$2.run(RealAppSyncSubscriptionCall.java:167)
        at java.lang.Thread.run(Thread.java:760)
02-09 12:22:37.719 5278-5965/com.rana.sahaj.myyu E/AndroidRuntime: FATAL EXCEPTION: Thread-91
    Process: com.rana.sahaj.myyu, PID: 5278
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall$Callback.onCompleted()' on a null object reference
        at com.apollographql.apollo.internal.RealAppSyncSubscriptionCall$2.run(RealAppSyncSubscriptionCall.java:167)
        at java.lang.Thread.run(Thread.java:760)
02-09 12:22:37.719 5278-5966/com.rana.sahaj.myyu E/AndroidRuntime: FATAL EXCEPTION: Thread-92
    Process: com.rana.sahaj.myyu, PID: 5278
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall$Callback.onCompleted()' on a null object reference
        at com.apollographql.apollo.internal.RealAppSyncSubscriptionCall$2.run(RealAppSyncSubscriptionCall.java:167)
        at java.lang.Thread.run(Thread.java:760)
02-09 12:22:37.719 5278-5967/com.rana.sahaj.myyu E/AndroidRuntime: FATAL EXCEPTION: Thread-93
    Process: com.rana.sahaj.myyu, PID: 5278
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall$Callback.onCompleted()' on a null object reference
        at com.apollographql.apollo.internal.RealAppSyncSubscriptionCall$2.run(RealAppSyncSubscriptionCall.java:167)
        at java.lang.Thread.run(Thread.java:760)

Environment(please complete the following information):

  • AppSync SDK Version: 2.7.+

Device Information (please complete the following information):
-Checked on Lolipop and Nougat

I think this is happening due to the below closing of subscription.

if (subscriptionWatcher!=null)
            subscriptionWatcher.cancel();

It was working on 2.6.+ version without any problem, I just updated it to 2.7+ version and app started crashing with the above error.

@mutablealligator mutablealligator self-assigned this Feb 11, 2019
@mutablealligator mutablealligator added the bug Something isn't working label Feb 11, 2019
@mutablealligator
Copy link

@SahajRana Sorry for the inconvenience caused. By any chance did you encounter the following log message in your Logcat?

Subscription Infrastructure: Callback passed into subscription [" + subscription +"] was null. Will not subscribe.

Can you post a code snippet where you create and invoke the subscription with a callback?

@mutablealligator mutablealligator added pending-response Issue is pending response from the issue requestor AppSync labels Feb 11, 2019
@scb01 scb01 self-assigned this Feb 12, 2019
@mutablealligator
Copy link

PR #117 fixes this issue. The next upcoming release should include this fix.

@frankmuellr frankmuellr added the pending-release Code has been merged but pending release label Feb 12, 2019
@SahajRana
Copy link
Author

@kvasukib thanks for the great response!, After I opened the issue I downgraded the version and then, after your request I changed it back to the newer version. But now, I'm not able to find the issue anymore. I think there could be some post upgrading files problem. I will let you guys know if I find it again, cheers!

@mutablealligator
Copy link

@SahajRana This fix has been released in 2.7.7 version of the SDK. Please upgrade and let us know any feedback you have.

@mutablealligator mutablealligator added closing-soon and removed pending-release Code has been merged but pending release labels Feb 13, 2019
@stale stale bot removed the closing-soon label Feb 13, 2019
@mutablealligator mutablealligator added closing-soon and removed pending-response Issue is pending response from the issue requestor labels Feb 13, 2019
@stale stale bot removed the closing-soon label Feb 13, 2019
@frankmuellr frankmuellr added the pending-response Issue is pending response from the issue requestor label Feb 13, 2019
@SahajRana
Copy link
Author

SahajRana commented Feb 15, 2019

@kvasukib I think this problem is resolved but now I'm getting another error and then app is crashed

02-15 14:46:07.918 29734-31104/com.xxx.xxx V/RealSubscriptionManager: Subscription Infrastructure: Attempting to reconnect
02-15 14:46:07.919 29734-31104/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: Thread-101
    Process: com.xxx.xxx, PID: 29734
    java.util.NoSuchElementException
        at java.util.HashMap$HashIterator.nextEntry(HashMap.java:854)
        at java.util.HashMap$KeyIterator.next(HashMap.java:885)
        at com.amazonaws.mobileconnectors.appsync.subscription.RealSubscriptionManager$3.run(RealSubscriptionManager.java:459)
        at java.lang.Thread.run(Thread.java:760)

@frankmuellr frankmuellr removed the pending-response Issue is pending response from the issue requestor label Feb 15, 2019
@SahajRana
Copy link
Author

@kvasukib @cbommas @muellerfr guys, the above error is pretty frequent and crashing an idle application after some time of opening.

@scb01
Copy link
Contributor

scb01 commented Feb 18, 2019

@SahajRana
Can you share code snippets of how you are creating the subscription, cancelling it etc., and your logcat? That will help in pinpointing why this crash is happening.

@mutablealligator mutablealligator added the investigating This issue is being investigated label Feb 18, 2019
@mutablealligator mutablealligator removed their assignment Feb 19, 2019
@SahajRana
Copy link
Author

SahajRana commented Feb 23, 2019

@cbommas, @kvasukib, @muellerfr Hey, this error is not easily trackable as it appears randomly, below is the code where the error is


                        //Initiate Retry if required
                        if (subscriptionToRetry != null) {
                            Log.v(TAG, "Subscription Infrastructure: Attempting to reconnect");
                            reconnectCountdownLatch = new CountDownLatch(1);
                 --> mApolloClient.subscribe(subscriptionToRetry.subscription).execute((AppSyncSubscriptionCall.Callback) subscriptionToRetry.getListeners().iterator().next());

                            try {
                                reconnectCountdownLatch.await(1, TimeUnit.MINUTES);
                            } catch (InterruptedException ioe) {
                                Log.v(TAG, "Subscription Infrastructure: Wait interrupted.");
                            }
                        }

Error::

02-23 16:46:14.403 9910-9910/xxx.xxx V/MqttSubscriptionClient: Subscription Infrastructure: Errror [Client is currently disconnecting (32102)] when disconnecting from topic [068151923254/csd4svqhmfedjj3pirtaaguxai/messageListener/a575609906dbeedbc8e68cfaf66e67047d791ab4820a827a67f1d7c3a151c013]
02-23 16:46:14.413 9910-9910/xxx.xxx D/MqttSubscriptionClient: Subscription Infrastructure: Successfully closed the connection. Client ID [n7utpcauqnfqrnp5gzjx4ozt4m]
02-23 16:46:14.413 9910-9910/xxx.xxx V/MqttSubscriptionClient: Subscription Infrastructure: client connection lost for client [n7utpcauqnfqrnp5gzjx4ozt4m]
    Subscription Infrastructure: Transmitting client connection lost for client [n7utpcauqnfqrnp5gzjx4ozt4m]
02-23 16:46:14.413 9910-9910/xxx.xxx V/RealSubscriptionManager: Subscription Infrastructure: onError called com.amazonaws.mobileconnectors.appsync.subscription.SubscriptionDisconnectedException: Client disconnected
02-23 16:46:14.413 9910-9910/xxx.xxx V/RealSubscriptionManager: Subscription Infrastructure: Disconnect received. Unexpected - Initiating reconnect sequence.
02-23 16:46:14.414 9910-9910/xxx.xxx V/RealSubscriptionManager: Subscription Infrastructure: Connection Error reported!
02-23 16:46:14.422 9910-10062/xxx.xxx I/RetryInterceptor: Returning network response: success
02-23 16:46:14.431 9910-10442/xxx.xxx V/RealSubscriptionManager: Subscription Infrastructure: Attempting to reconnect
02-23 16:46:14.432 9910-10442/xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: Thread-100
    Process: com.rana.sahaj.myyu, PID: 9910
    java.util.NoSuchElementException
        at java.util.HashMap$HashIterator.nextEntry(HashMap.java:854)
        at java.util.HashMap$KeyIterator.next(HashMap.java:885)
        at com.amazonaws.mobileconnectors.appsync.subscription.RealSubscriptionManager$3.run(RealSubscriptionManager.java:459)
        at java.lang.Thread.run(Thread.java:760)
02-23 16:46:14.436 9910-10442/xxx.xxx E/SahajLOG008: UNCAUGHT Called

@SahajRana
Copy link
Author

@cbommas @kvasukib please have a look as we are moving to production pretty soon so it would be a real problem if the application crashes!

@paulfthomas
Copy link

I'm encountering the same issue with the version 2.7.7:

java.util.NoSuchElementException
        at java.util.HashMap$HashIterator.nextEntry(HashMap.java:808)
        at java.util.HashMap$KeyIterator.next(HashMap.java:833)
        at com.amazonaws.mobileconnectors.appsync.subscription.RealSubscriptionManager$3.run(RealSubscriptionManager.java:459)
        at java.lang.Thread.run(Thread.java:841)

Downgrading to 2.7.6 solves it but the initial bug described by @SahajRana reappears.

@scb01 scb01 changed the title Subscription crashing application due to "AppSyncSubscriptionCall$Callback.onCompleted()" NPE Subscription crashing application due to "java.util.NoSuchElementException" exception Feb 26, 2019
@scb01
Copy link
Contributor

scb01 commented Feb 26, 2019

@SahajRana, @paulfthomas

The latest release of the SDK, 2.7.8, has logic to protect against this crash. The crash appears to be due to a race condition between a subscription cancellation and subscription re-connection logic.

I wasn't able to reproduce this locally, as this is somewhat of a tricky one to reproduce. Could give the latest rev a try and let me know if resolves the issue?

@scb01 scb01 added pending-response Issue is pending response from the issue requestor and removed investigating This issue is being investigated labels Feb 26, 2019
@paulfthomas
Copy link

@cbommas it seems that 2.7.8 resolves the issue 👍

@scb01
Copy link
Contributor

scb01 commented Feb 26, 2019

@paulfthomas

Excellent! thank you for confirming. I will go ahead and close this out. Please feel free to post back on this thread if you or @SahajRana run into further issues.

@scb01 scb01 closed this as completed Feb 26, 2019
@SahajRana
Copy link
Author

@cbommas yes, it seems from my side as well that it's fixed. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

5 participants