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

NullPointerException in PresenceChannelImpl.java causing a crash #286

Closed
lordcodes opened this issue Sep 11, 2020 · 11 comments · Fixed by #290
Closed

NullPointerException in PresenceChannelImpl.java causing a crash #286

lordcodes opened this issue Sep 11, 2020 · 11 comments · Fixed by #290

Comments

@lordcodes
Copy link

What is the issue?

A NullPointerException is occurring within the PresenceChannelImpl implementation when extracting presence data from a received message. This is causing our app to crash for quite a few users. I will need to somehow find a way to catch this error to avoid the app crashing in the short-term.

Is it a crash report? Submit stack traces or anything that you think would help

Here is the stack trace from our error reporting:

Fatal Exception: java.lang.NullPointerException
throw with null exception
com.pusher.client.channel.impl.PresenceChannelImpl.handleSubscriptionSuccessfulMessage (PresenceChannelImpl.java:101)
com.pusher.client.channel.impl.PresenceChannelImpl.onMessage (PresenceChannelImpl.java:58)
com.pusher.client.channel.impl.ChannelManager.onMessage (ChannelManager.java:116)
com.pusher.client.connection.websocket.WebSocketConnection.handleEvent (WebSocketConnection.java:177)
com.pusher.client.connection.websocket.WebSocketConnection.access$600 (WebSocketConnection.java:27)
com.pusher.client.connection.websocket.WebSocketConnection$6.run (WebSocketConnection.java:261)
com.pusher.client.util.Factory$1.run (Factory.java:119)

In onMessage when the message is a subscription success, it tries to extract the presence data from the event. This data seems to come back as null, but the code isn't handling that case and so a NullPointerException is thrown.

PresenceChannelImpl.java

private void handleSubscriptionSuccessfulMessage(final String message) {
        // extract data from the JSON message
        final PresenceData presenceData = extractPresenceDataFrom(message);
Line 101. CRASH HERE  --->  final List<String> ids = presenceData.ids;

Any improvements you suggest

Only improvement is to not crash.

Let me know if you need more information, although not sure what else I can see, due to the whole stack-trace being entirely within Pusher code and being when subscription succeeds, as opposed to a message triggered by the app.


CC @pusher/mobile

@jonathanlloyd
Copy link
Contributor

jonathanlloyd commented Sep 18, 2020

Hi @lordcodes - I'm investigating this, but I'm struggling to reproduce the issue.
Do you have any more information on how presence channels are used in your app/a snippet that can reproduce the crash?

Also, would you mind telling me what version of the SDK you are using?

@lordcodes
Copy link
Author

lordcodes commented Sep 18, 2020

Hi @jonathanlloyd. I raised a Pusher support ticket alongside the GitHub issue including various bits of information (22613).

The crash happens when subscribing to the presence channel, therefore it is before we do anything with the channel. This means it doesn't matter what you actually do with the channel, crash happens before you even get to that.

We are using the latest released version of the SDK (2.2.5).

From the stack-trace, you can see that it crashes with an NPE when using the 'PresenceData' returned from extractPresenceDataFrom(message). This suggests, that the object is failing to parse from JSON, I would have thought this is a possible situation, so probably best this case is handled so that it at least doesn't crash.

Beyond this I guess, it is worth looking into how it is possible for a subscription message to be sent that doesn't deserialize properly into the PrescenceData.

I appreciate it is hard to reproduce, it seems to happen for a subset of users in a subset of sessions. It is also worth saying if you reproduced it, you would just get a stack-trace that said the presence data was null and an NPE like I sent over. I do appreciate you would like to reproduce it though.

@Rexee
Copy link

Rexee commented Feb 23, 2021

We had similar issue. Source was - we used Android Studio alpha or beta d8 (ex proguard). As I understood - this new beta d8 removed or modified java bytecode, which cause this error. Rolling back to stable Android Studio completely solved this issue.

@lordcodes
Copy link
Author

lordcodes commented Feb 23, 2021 via email

@Rexee
Copy link

Rexee commented Feb 23, 2021

I’ve always been using the latest stable Android Studio and Gradle plugin, same on CI where our release builds are built. This crash happened to us in production.

On Tue, 23 Feb 2021 at 07:30, Rexee @.***> wrote: We had similar issue. Source was - we used Android Studio alpha or beta d8 (ex proguard). As I understood - this new beta d8 removed or modified java bytecode, which cause this error. Rolling back to stable Android Studio completely solved this issue. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#286 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACWLLEYT6PVVFTRNVLXFHT3TANKQFANCNFSM4RGYYBWQ .

I'm just describing how this appear and how it's been solved. You can believe or not, but changing AS version solves issue. So I think it's some problem with proguard/d8 bytecode manipulations.

@lordcodes
Copy link
Author

lordcodes commented Feb 23, 2021 via email

@lordcodes
Copy link
Author

@danielrbrowne Fantastic, thank you. Will update when the next release is out and re-enable our presence channel functionality.

Does the fix suggest one of our other clients was sending malformed data on the presence channel or an edge-case where invalid data is received on the websocket?

@danielrbrowne
Copy link
Contributor

@lordcodes It remains unclear what was the exact cause of this malformed data (I got drafted in on this issue only recently, and I'm by trade an iOS engineer, so some of the context was missing), however this does look to have been a bit of an edge case. This is why this was previously left unhandled.

I am working on a new 2.2.6 patch release ASAP.

@lordcodes
Copy link
Author

@danielrbrowne Thank you, I appreciate the reply. I could tell it is very much an edge case, however, somehow it was happening quite often for our users. The fix should allow us to put back the presence channel functionality which is great!

@danielrbrowne
Copy link
Contributor

@lordcodes v2.2.6 with this fix included, is now released!

@lordcodes
Copy link
Author

@danielrbrowne Fantastic, thanks. Will update and re-enable logic when I can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants