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: register data provider listener only if it has not been registered #11471

Merged
merged 4 commits into from
Aug 10, 2021

Conversation

TatuLund
Copy link
Contributor

Copy link
Contributor

@denis-anisimov denis-anisimov left a comment

Choose a reason for hiding this comment

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

This looks good but I spent some time to understand why it's needed.
From the code I see paired handleDetach method which do the clean up.
So assuming the expected workflow detach should always happen after attach and this check should not be needed at all.

The problem is in the method names which are uses in two cases:

  • when the node is attached/detached (this is a normal expected workflow). And method names are fine for this situation.
  • when data provider is set: handleDetach and then handleAttach are called .

In the second case the method names are not suitable. Since the same methods are used in two totally different cases they should be renamed.

This is one thing which I would like to see changed here.

Another : it's still not obvious that setDataProvider resets the listener in the same way as attach/detach does.
So even though the null check is quite safe change I would like to see a unit test which will allow to prevent introducing such regression back.

@Legioth
Copy link
Member

Legioth commented Jul 29, 2021

This looks good but I spent some time to understand why it's needed.

That's because the PR doesn't contain any tests

@Legioth
Copy link
Member

Legioth commented Jul 29, 2021

The conventional way of dealing with cases like this is to remove() the old registration if one exists before writing a new value to the field, instead of assuming that the old registration can be reused. That approach is slightly more robust since it would also cover the case of changing from one data provider to another without "detach" in between - this isn't present in the code today but there's no guarantee that it won't occur as a result of future changes.

@TatuLund
Copy link
Contributor Author

@Legioth , good point, I improved my solution.

@vaadin-bot vaadin-bot added +0.1.0 and removed +0.0.1 labels Jul 30, 2021
@mshabarov
Copy link
Contributor

@TatuLund I'm going to add a test for this fix to move this important change forward, so if you currently are working on it also, please let me know :)

@TatuLund
Copy link
Contributor Author

TatuLund commented Aug 6, 2021

@mshabarov Please do, I have not figured out good test yet.

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 2 issues

  1. MAJOR DataCommunicator.java#L1075: Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. rule
  2. INFO DataCommunicator.java#L483: Complete the task associated to this TODO comment. rule

@denis-anisimov denis-anisimov merged commit 067f63f into master Aug 10, 2021
@denis-anisimov denis-anisimov deleted the fix-grid-1914 branch August 10, 2021 06:44
vaadin-bot pushed a commit that referenced this pull request Aug 10, 2021
…ed (#11471)

* fix: register data provider listener only if it has not been registered yet

fixes: vaadin/flow-components#1914

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
@vaadin-bot
Copy link
Collaborator

Hi @TatuLund and @denis-anisimov, when i performed cherry-pick to this commit to 2.7, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick 067f63f
error: could not apply 067f63f... fix: register data provider listener only if it has not been registered (#11471)
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

vaadin-bot pushed a commit that referenced this pull request Aug 10, 2021
…ed (#11471)

* fix: register data provider listener only if it has not been registered yet

fixes: vaadin/flow-components#1914

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
@vaadin-bot
Copy link
Collaborator

Hi @TatuLund and @denis-anisimov, when i performed cherry-pick to this commit to 2.6, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick 067f63f
error: could not apply 067f63f... fix: register data provider listener only if it has not been registered (#11471)
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add ' or 'git rm '
hint: and commit the result with 'git commit'

vaadin-bot added a commit that referenced this pull request Aug 10, 2021
…ed (#11471) (#11546)

* fix: register data provider listener only if it has not been registered yet

fixes: vaadin/flow-components#1914

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>

Co-authored-by: Tatu Lund <tatu@vaadin.com>
Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
vaadin-bot added a commit that referenced this pull request Aug 10, 2021
…ed (#11471) (#11547)

* fix: register data provider listener only if it has not been registered yet

fixes: vaadin/flow-components#1914

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>

Co-authored-by: Tatu Lund <tatu@vaadin.com>
Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
mshabarov added a commit that referenced this pull request Aug 11, 2021
pleku pushed a commit that referenced this pull request Aug 11, 2021
vaadin-bot pushed a commit that referenced this pull request Aug 11, 2021
vaadin-bot pushed a commit that referenced this pull request Aug 11, 2021
mshabarov added a commit that referenced this pull request Aug 11, 2021
…registered (#11471)" (#11555)

This reverts commit 067f63f

(cherry picked from commit c1a75e6)
vaadin-bot added a commit that referenced this pull request Aug 11, 2021
…registered (#11471)" (#11555) (#11557)

This reverts commit 067f63f

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
vaadin-bot added a commit that referenced this pull request Aug 11, 2021
…registered (#11471)" (#11555) (#11558)

This reverts commit 067f63f

Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
mshabarov added a commit to vaadin/flow-components that referenced this pull request Aug 17, 2021
Removes the old data provider listener and adds a new one upon setting up a data provider and attaching a component to the page.
Reorders and makes the 'rebuild' method for ListBox not to being called in attach handler method, because it leads to loosing the data in cache.

Follows up the memory leak issue in Flow (vaadin/flow#11471) and fixes the regression in components caused by the change in Flow.

Related-to #1914.
mshabarov pushed a commit that referenced this pull request Aug 17, 2021
…ed (#11471)

* fix: register data provider listener only if it has not been registered yet

fixes: vaadin/flow-components#1914

Co-authored-by: Mikhail Shabarov <mikhail@vaadin.com>
(cherry picked from commit 067f63f)
mshabarov added a commit to vaadin/flow-components that referenced this pull request Aug 18, 2021
Removes the old data provider listener and adds a new one upon setting up a data provider and attaching a component to the page.
Reorders and makes the 'rebuild' method for ListBox not to being called in attach handler method, because it leads to loosing the data in cache.

Follows up the memory leak issue in Flow (vaadin/flow#11471) and fixes the regression in components caused by the change in Flow.

Related-to #1914.

(cherry picked from commit d47cce4)
pleku pushed a commit to vaadin/flow-components that referenced this pull request Aug 19, 2021
…2012)

Removes the old data provider listener and adds a new one upon setting up a data provider and attaching a component to the page.
Reorders and makes the 'rebuild' method for ListBox not to being called in attach handler method, because it leads to loosing the data in cache.

Follows up the memory leak issue in Flow (vaadin/flow#11471) and fixes the regression in components caused by the change in Flow.

Related-to #1914.

(cherry picked from commit d47cce4)
mshabarov added a commit to vaadin/flow-components that referenced this pull request Aug 19, 2021
…2012)

Removes the old data provider listener and adds a new one upon setting up a data provider and attaching a component to the page.
Reorders and makes the 'rebuild' method for ListBox not to being called in attach handler method, because it leads to loosing the data in cache.

Follows up the memory leak issue in Flow (vaadin/flow#11471) and fixes the regression in components caused by the change in Flow.

Related-to #1914.

(cherry picked from commit d47cce4)
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha2 and is also targeting the upcoming stable 22.0.0 version.

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.

Memory leak when repeatedly setting DataProvider
5 participants