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: git#865 - fixes notifying the switch atSign event multiple times #867

Merged
merged 13 commits into from
Jan 10, 2023

Conversation

sitaram-kalluri
Copy link
Member

@sitaram-kalluri sitaram-kalluri commented Jan 5, 2023

- What I did

  • Remove the inactive listeners from AtClientManager._changeListeners list.
  • Add unit tests to assert the changes.
  • (gkc) Some further simplifications to code associated with switching atSigns

- How I did it

  • Added removeChangeListener method in AtClientManager, that removes the given instance of AtSignChangeListener from AtClientManager._changeListeners list
  • In AtClientManager._notifyListeners added a line that clones the _changeListeners list and iterate on the cloned list to avoid the concurrent modification exception.
  • Some changes to simplify code
    • fix: Added check to SwitchAtSignEvent constructor to prevent events being created when the atClients are the same
    • debug: Added a logger to AtClientManager. Log INFO when switching atSigns
    • refactor: Removed instance variable _previousAtClient from AtClientManager. Instead, determine previousAtClient within the setCurrentAtSign method
    • fix: Added duplicate check to AtClientManager.listenToAtSignChange
    • fix: Changed _currentAtClient from late to being nullable to prevent uninitialized check in setCurrentAtSign
    • fix: AtClientManager now calls _notifyListeners before creating the new NotificationServiceImpl and SyncServiceImpl. This allows those classes' implementations of listenToAtSignChange to be simplified
    • refactor: Removed static maps of instances in NotificationServiceImpl and SyncServiceImpl thus allowing some code simplification
    • refactor: Simplified NotificationServiceImpl.listenToAtSignChange
    • refactor: Simplified SyncServiceImpl.listenToAtSignChange, and added code to close the RemoteSecondary's AtLookUp's connection if there is one

- How to verify it

  • On the switch atSign event, AtClientManager._changeListeners should not have obsolete listeners.

- Description for the changelog

  • Remove the inactive listeners from AtClientManager._changeListeners list.

@sitaram-kalluri
Copy link
Member Author

Found the root cause of failing end2end_tests. Will fix the issue and push the changes.

@sitaram-kalluri sitaram-kalluri force-pushed the unregister_change_listeners branch 2 times, most recently from 759895b to a4b8c0b Compare January 5, 2023 15:40
@sitaram-kalluri sitaram-kalluri marked this pull request as ready for review January 5, 2023 16:04
gkc
gkc previously requested changes Jan 6, 2023
Copy link
Contributor

@gkc gkc left a comment

Choose a reason for hiding this comment

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

As discussed just now, we don't need the 'isActive' flag. The concurrent modification error can be eliminated by having _notifyListeners make a copy of the _changeListeners and iterate through the copy of the list rather than through the list itself.

As a side note - force-pushing your branch is masking useful information about the evolution of the code - without seeing the interim commits, it was completely unclear to me why the isActive flag was added until we had our discussion. Is there a reason you prefer force-push?

@sitaram-kalluri
Copy link
Member Author

As discussed just now, we don't need the 'isActive' flag. The concurrent modification error can be eliminated by having _notifyListeners make a copy of the _changeListeners and iterate through the copy of the list rather than through the list itself.

As a side note - force-pushing your branch is masking useful information about the evolution of the code - without seeing the interim commits, it was completely unclear to me why the isActive flag was added until we had our discussion. Is there a reason you prefer force-push?

@gkc: Sure, will update the code as per our discussion. I generally do a force push to keep the commit history clean. However, I do it only when there are no review comments/discussions on the PR. If there are review comments/discussions on the PR I avoid doing a force push.

@gkc
Copy link
Contributor

gkc commented Jan 6, 2023

@gkc: Sure, will update the code as per our discussion. I generally do a force push to keep the commit history clean. However, I do it only when there are no review comments/discussions on the PR. If there are review comments/discussions on the PR I avoid doing a force push.

I understand. However sometimes (as in this case), squashing the commits makes it impossible to understand how you got to a particular design / implementation decision, without having a conversation.

@sitaram-kalluri
Copy link
Member Author

@gkc: Sure, will update the code as per our discussion. I generally do a force push to keep the commit history clean. However, I do it only when there are no review comments/discussions on the PR. If there are review comments/discussions on the PR I avoid doing a force push.

I understand. However sometimes (as in this case), squashing the commits makes it impossible to understand how you got to a particular design / implementation decision, without having a conversation.

Ok Gary, Will avoid force pushing to the branch.

VJag
VJag previously approved these changes Jan 10, 2023
…eing created when the atClients are the same

debug: Added a logger to AtClientManager. Log INFO when switching atSigns
refactor: Removed instance variable _previousAtClient from AtClientManager. Instead, determine previousAtClient within the setCurrentAtSign method
fix: Added duplicate check to AtClientManager.listenToAtSignChange
fix: Changed _currentAtClient from `late` to being nullable to prevent uninitialized check in setCurrentAtSign
fix: AtClientManager now calls _notifyListeners before creating the new NotificationServiceImpl and SyncServiceImpl
refactor: Removed static maps of instances in NotificationServiceImpl and SyncServiceImpl thus allowing some code simplification
refactor: Simplified NotificationServiceImpl.listenToAtSignChange
refactor: Simplified SyncServiceImpl.listenToAtSignChange, and added code to close the RemoteSecondary's AtLookUp's connection if there is one
@gkc
Copy link
Contributor

gkc commented Jan 10, 2023

@VJag Have made some further changes to this branch in 0db8b2b ... please review

@gkc gkc requested review from VJag and gkc and removed request for gkc January 10, 2023 13:10
@sitaram-kalluri sitaram-kalluri merged commit 8450241 into trunk Jan 10, 2023
@sitaram-kalluri sitaram-kalluri deleted the unregister_change_listeners branch January 10, 2023 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AtClientManager notifies multiple times on the switch atSign event.
3 participants