-
-
Notifications
You must be signed in to change notification settings - Fork 792
Fix: Prevent notification count overflow when memory is low #5230
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
base: main
Are you sure you want to change the base?
Fix: Prevent notification count overflow when memory is low #5230
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @anvithagowda098,
Thanks for your contribution. I have a few suggestions to improve your current approach:
- The current use of Int.max / 10 to limit the notification count masks the underlying memory issue. Since a realistic notification count for Wikimedia projects is much lower, displaying such a cap may hide the fact that there's an overflow or an error in the count computation when fetching this info.
- Updating previousUnreadCount with the fetched count regardless of its correctness means that if the number is incorrect (e.g., due to overflow in this case), it will be stored and used as a fallback. We should update and cache it only if the count is correct.
Tips for approaching this issue:
-
After fetching the count, verify if it is within a realistic threshold (for instance, less than 1000). If the count exceeds this value, it likely indicates an underlying problem.
-
If the count is abnormally high, log an error or try to re-check it. This will help identify and diagnose the root cause.
-
Only update previousUnreadCount if the count passes the validation check. Otherwise, continue using the last known good value.
-
Take a closer look at modelController.numberOfUnreadNotifications() to determine if the overflow is due to low memory conditions, a fetching error, or an NSNumber casting issue.
Let me know if you have any questions or need any help.
@mazevedofs Thanks for the feedback! I’ve made the requested changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the current solution probably prevents erroneous display values, it still doesn’t address the underlying issue causing the overflow. If low memory conditions are the source, I believe it’s worth investigating why we get this int overflow to solve the root cause.
WMF Framework/Remote Notifications/RemoteNotificationsController.swift
Outdated
Show resolved
Hide resolved
WMF Framework/Remote Notifications/RemoteNotificationsController.swift
Outdated
Show resolved
Hide resolved
WMF Framework/Remote Notifications/RemoteNotificationsController.swift
Outdated
Show resolved
Hide resolved
WMF Framework/Remote Notifications/RemoteNotificationsController.swift
Outdated
Show resolved
Hide resolved
WMF Framework/Remote Notifications/RemoteNotificationsController.swift
Outdated
Show resolved
Hide resolved
Thanks for the thorough review @mazevedofs ! |
Hi @anvithagowda098. I found this tutorial on how to simulate the low memory environment on simulator https://www.avanderlee.com/debugging/no-space-left-on-device/ |
@mazevedofs I've made requested changes |
Hi @anvithagowda098! Thanks for addressing the changes! Were you able to investigate what caused the integer overflow in the first place? Did simulating a low-memory device help? Let me know if you were able to reproduce the bug in the first place - I understand it's a difficult scenario to simulate. |
@mazevedofs I have my university exams going on currently |
@mazevedofs Hey! I was able to successfully simulate a low memory environment with the help of the tutorial you provided. I couldn't reproduce the issue though. Either it's already resolved or doesn't occur under this condition. That said, this patch ensures that incorrect values are not displayed, offering a safeguard against similar scenarios. |
Phabricator:
https://phabricator.wikimedia.org/T385130
Notes
Test Steps