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

Opening a notification for nonexistent user/stream causes crash #4309

Open
gnprice opened this issue Nov 12, 2020 · 6 comments
Open

Opening a notification for nonexistent user/stream causes crash #4309

gnprice opened this issue Nov 12, 2020 · 6 comments
Labels
a-notifications help wanted severe: crash The app quits, or stops responding.

Comments

@gnprice
Copy link
Member

gnprice commented Nov 12, 2020

This is a situation that's only possible in the first place when caused by some bug in either the app or the server. But such bugs happen, and particularly because it involves the server, we should be robust enough not to crash on it.

I don't think there's a known way to trigger this with a current version from master (or with today's release v27.157, now in alpha) and a stock server. But one way to trigger it is by reproducing #4290 on the current production release, v27.156. As described at #4290 (comment) , the app crashes, and (on Android) adb logcat shows output like this:

11-12 14:38:49.964 27558 27719 W ReactNativeJS: notification realm_uri not found in accounts
11-12 14:38:49.965 27558 27719 W ReactNativeJS:     realm_uri: "https://chat.zulip.org"
11-12 14:38:49.965 27558 27719 W ReactNativeJS:     known_urls: …
11-12 14:38:50.002 27558 27719 E ReactNativeJS: Error: getUserForEmail: missing user: email …

That is, we try to navigate to the right conversation as if it were on the active account... and when there isn't a user by that email, we crash.

Instead, we should handle this in getNarrowFromNotificationData -- that's the place where we take the raw names/IDs the server put in the notification and turn them into values we'll pass around to the "soft center" of our normal app code which assumes the data it gets is well-formed.

In getNarrowFromNotificationData, we should confirm that the specified user(s) or stream exist in our data. If they don't, then treat it much like we do in getAccountFromNotificationData:

  • Log a warning (to Sentry.)
  • Return null, to skip trying to do anything with the data.

That way the app will be open and running, and not crashed.

@gnprice
Copy link
Member Author

gnprice commented Dec 23, 2020

I don't think there's a known way to trigger this with a current version from master (or with today's release v27.157, now in alpha) and a stock server.

A correction: this bug can be triggered on v27.157 by interacting with this remaining piece of #2295 (quoting my description at #2295 (comment) ):

  • If the user has several known accounts in the same realm, we
    don't switch to either of them, because we can't tell which.

So if you've been using one realm/org; and you get a notification for a different one; and you have multiple known accounts in that other realm; then we don't switch to it, we stay in the wrong realm/org, and so we end up exercising this bug and crashing.

@gnprice
Copy link
Member Author

gnprice commented Dec 23, 2020

I believe this is now fixed for PMs, by commits bed2f2a and e9941c0 (PRs #4335 and #4346). If we don't have data on one of the participants in the PM conversation, getNarrowFromNotificationData will return null and we simply won't attempt the narrow.

I haven't tested that empirically, though.

Still open for notifications for stream messages -- we'll attempt to navigate to the given conversation, and if we can't find the stream (by name), then I expect that will crash.

Before we close this issue, we should also have a comment in the code saying it's important that it checks for the users existing. As it stands, that check for PMs is basically a side effect of the fact that our Narrow constructors for PM conversations demand both emails and user IDs.

@chrisbobbe
Copy link
Contributor

I've just posted a few questions on CZO.

@gnprice
Copy link
Member Author

gnprice commented Apr 13, 2021

Looking in Sentry, this isn't something that's happening to lots of users.

But it is pretty bad when it happens, so would still be good to fix. And I think with the plan at the end of the issue description above, it won't be very complicated to fix.

@chrisbobbe
Copy link
Contributor

I've just posted a few questions on CZO.

I think progress doesn't have to block on reading and understanding this thread.

@WesleyAC
Copy link
Contributor

WesleyAC commented Jun 21, 2021

Is this this issue in Sentry? If so, it's happening pretty often.

I did find a interesting example — a selfhosted realm, where the URL known_urls gives a 301 redirect to the realm_uri/parsed_url. (link, and another).

So, that sort of makes sense as an explanation for this. The server got moved, but we didn't update known_urls when that happened.

Another thing I see is where the URL in known_urls is https://example.com/, but the realm_uri is https://example.com (with no slash). That seems like something we should detect as well. (link)

Here's an odd case where known_urls had https://example.com/join/<invite link hash stuff>, the passed_url is https://example.com/, and the realm_uri is https://example.com.

WesleyAC added a commit to WesleyAC/zulip-mobile that referenced this issue Jun 21, 2021
We had a steady stream of errors in Sentry caused by differences between
the `known_urls` and `realm_uri`, where one of those had an extra `/` on
the end (or some more surprising junk, such as a `/join/` link). Since
we don't support running Zulip on a non-root path [1], we can simply
compare the domain instead of the href. This is probably more of a
band-aid than a real fix (we should figure out how the strange values
get into `known_urls` and fix that), but we might as well just check the
domain, since the path doesn't matter.

Related: zulip#4309.

[1] https://chat.zulip.org/#narrow/stream/3-backend/topic/support.20for.20running.20on.20non-webroot.20url.3F
WesleyAC added a commit to WesleyAC/zulip-mobile that referenced this issue Jun 21, 2021
We had a steady stream of errors in Sentry caused by differences between
the `known_urls` and `realm_uri`, where one of those had an extra `/` on
the end (or some more surprising junk, such as a `/join/` link) [1].
Since we don't support running Zulip on a non-root path [2], we can
simply compare the domain instead of the href. This is probably more of
a band-aid than a real fix (we should figure out how the strange values
get into `known_urls` and fix that), but we might as well just check the
domain, since the path doesn't matter.

Related: zulip#4309.

[1] zulip#4309 (comment)
[2] https://chat.zulip.org/#narrow/stream/3-backend/topic/support.20for.20running.20on.20non-webroot.20url.3F
WesleyAC added a commit to WesleyAC/zulip-mobile that referenced this issue Jun 22, 2021
We had a steady stream of errors in Sentry caused by differences between
the `known_urls` and `realm_uri`, where one of those had an extra `/` on
the end (or some more surprising junk, such as a `/join/` link) [1].
Since we don't support running Zulip on a non-root path [2], we can
simply compare the domain instead of the href. This is probably more of
a band-aid than a real fix (we should figure out how the strange values
get into `known_urls` and fix that), but we might as well just check the
domain, since the path doesn't matter.

Related: zulip#4309.

[1] zulip#4309 (comment)
[2] https://chat.zulip.org/#narrow/stream/3-backend/topic/support.20for.20running.20on.20non-webroot.20url.3F
WesleyAC added a commit that referenced this issue Jul 2, 2021
We had a steady stream of errors in Sentry caused by differences between
the `known_urls` and `realm_uri`, where one of those had an extra `/` on
the end (or some more surprising junk, such as a `/join/` link) [1].
Since we don't support running Zulip on a non-root path [2], we can
simply compare the domain instead of the href. This is probably more of
a band-aid than a real fix (we should figure out how the strange values
get into `known_urls` and fix that), but we might as well just check the
domain, since the path doesn't matter.

Related: #4309.

[1] #4309 (comment)
[2] https://chat.zulip.org/#narrow/stream/3-backend/topic/support.20for.20running.20on.20non-webroot.20url.3F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-notifications help wanted severe: crash The app quits, or stops responding.
Projects
None yet
Development

No branches or pull requests

3 participants