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

Fix rewards extension state (notifications) array attempt to set by named property #2407

Merged
merged 1 commit into from
May 11, 2019

Conversation

petemill
Copy link
Member

@petemill petemill commented May 9, 2019

Causes 100% cpu loop

Fix brave/brave-browser#4344

Submitter Checklist:

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@petemill petemill requested review from bsclifton and NejcZdovc May 9, 2019 22:45
@petemill petemill self-assigned this May 9, 2019
if (!notifications) {
notifications = []
if (!notifications || Array.isArray(notifications)) {
notifications = {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix. @NejcZdovc can you explain better about:

  • why this was an array
  • what the repeatable case could be to get in this state where either notification is blank or existing state.notifications is an array (which was my case - state.notifications was already []) so that we can get a test plan

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petemill line 155 in this same file seems to set it, line 168 merges it back into state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that I copied it from line 156 where we set it to array and I guess that was problematic as well. So I think we need to fix line 156 as well. You can see that in tests that I added it was expected to be an object 9cecb15#diff-f250acb8ae40c4d514754045d9b6e936R379.

Not sure as why only few people see this problem as it should break for everyone

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbondy @NejcZdovc that in L155 also needs to change, right? It's invalid to create this property as an array when it's used as an object.

Copy link
Member Author

@petemill petemill May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NejcZdovc would only be a problem if state.notifications does not yet exist, right? Do we persist this f/e redux state to disk? Me, personally, I 'upgraded' the profile from dev to nightly before experiencing this bug, if that helps

Copy link
Member Author

@petemill petemill May 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type in L153 also appears to be incorrect, and assume that notification ID is always a number:

let notifications: Record<number, RewardsExtension.Notification> = state.notifications

...but even then it assigns an empty array to that type. I doubt that should pass typescript compile... 🤷‍♂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup we need to change line 155. It's strange why it would work for some and not work for others. Also we had this code (line 155) in there for ages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember the specific details, but wondering if this is fallout from the notifications type change. I seem to recall they were initially integers and then switched to strings. I wonder if that caused a problem and/or wasn't fully refactored...

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed fix works great using my broken profile 😄! I would approve, but I think @NejcZdovc should respond (so that this doesn't get merged on accident)

@NejcZdovc would be good to find when this started, so we know how far back to uplift. I suspect it started with 0.66.x (which is now DEV)

@NejcZdovc
Copy link
Contributor

@bsclifton this was introduced with brave/brave-browser#2914, so we would need to uplift to 0.64

type: notification.type,
timestamp: notification.timestamp,
args: notification.args
for (const notificationItemData of list) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this change is needed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, this was just cleanup to aid readability when diagnosing the bug

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we revert back to what it was so that change is really minimal as we will probably need to uplift it into beta

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on revert back, just to minimize patch (even though it's arguably nicer; I always avoid forEach since you can't break out)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was wondering if this was part of the bug in case payload.list is actually the same item in memory as state.notifications, and then it was modifying the list that was being iterating over.... I don't think so though if it's always coming from c++, but I can't vouch for that. I'll revert this, but I did check that this is unchanged down to at least 0.65, and it is unchanged...

@petemill petemill force-pushed the fix-rewards-extension-notifications-hang branch 3 times, most recently from 329e9dc to 5da66ce Compare May 10, 2019 05:46
@petemill
Copy link
Member Author

After this fix, my local profile still shows 10 notifications in the badge (and there are 10 notification items in the state), but there are no actual notifications to be seen, in the panel or the rewards settings page. I wonder if that's due to using a production profile in the development build @NejcZdovc ?

bsclifton
bsclifton previously approved these changes May 10, 2019
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pulled latest, fix works great 👍

Same as @petemill, the notification count never gets cleared. So I'm stuck with 28 notifications?
(I'm also using my Brave-Browser-Nightly profile copied over to Brave-Browser-Development

@NejcZdovc
Copy link
Contributor

NejcZdovc commented May 10, 2019

let's wait with merge please. Can you please paste array that you received as payload into this reducer. Would like to see what are these 10 notifications?

Update: @petemill provided array to me so will check out why this could be a problem and why we wouldn't display them if we get them. If I don't find anything for it in the next few hours I would suggest to merge it and uplift it asap so we remove CPU problem for the users.

@bsclifton bsclifton force-pushed the fix-rewards-extension-notifications-hang branch from 5da66ce to eb6313c Compare May 11, 2019 00:38
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux and Windows tests passed; macOS didn't run because of version mismatch. I pulled locally and built/ran unit tests/ran browser tests/ran test-security and all passed great 😄👍

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

Successfully merging this pull request may close these issues.

Rewards extension icon does not respond to clicks
5 participants