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

Race condition in loading contacts can cause previously selected contact to load #7250

Closed
Tracked by #88
dianabarsan opened this issue Aug 11, 2021 · 3 comments
Closed
Tracked by #88
Assignees
Labels
Type: Bug Fix something that isn't working as intended
Milestone

Comments

@dianabarsan
Copy link
Member

dianabarsan commented Aug 11, 2021

Describe the bug
Contacts page could end up loading the previously loaded contact if a contact change is received just prior to the contact being de-selected.

To Reproduce
This is very hard to reproduce with actual usage, but it has been causing a wdio e2e test to fail intermittently.
Example of failure is: https://github.com/medic/cht-core/runs/3297387483?check_suite_focus=true#step:18:282
This failure is quite common (once every 10 suites?).

Expected behavior
The selected contact shouldn't be changed the the previously selected contact.

Environment

  • Instance: GHA Virtual machine
  • App: webapp
  • Version: 3.12

Additional context
I added helper logs in the code, so I better understand what's going on, and reran the test locally until I got a failure. This is what is happening:

routing to contact "health_center_uuid"
selecting contact "health_center_uuid"
set selected contact "health_center_uuid"
contact receives external change "health_center_uuid"
selecting contact "health_center_uuid"
set selected contact null <- navigating away from the contact content page, in the case of the test, we route to contact-edit to add a new contact
set selected contact "health_center_uuid" <- the callback from the external change contact load updates the state with the old contact, so the next time we load the contacts content component, the state is actually dirty!
routing to contact "clinic_uuid" <- loading another contact 
selecting contact "clinic_uuid"
contact receives external change "health_center_uuid" <- because the state is dirty when we load the component, the code reacts to a change of the previously selected contact
selecting contact "health_center_uuid"
set selected contact "clinic_uuid"
set selected contact "health_center_uuid"
@dianabarsan dianabarsan added the Type: Bug Fix something that isn't working as intended label Aug 11, 2021
@dianabarsan
Copy link
Member Author

I just realized I had already created an issue for the flaky e2e test:#7244

@latin-panda
Copy link
Contributor

This is how I was able to see the problem:

  • login as an online user
  • set the network slow
  • watch the log of actions to see the value of selectedContact in Store
  • move from "contact view" to "contact edit", back and forth many times and quickly, but at the end land in "contact edit"
  • make sure you've waited for all the logs to finish printing.
  • observe when in "contact edit page" the selectedContact from the store is set to the last contact view data. The expected is to be null.

I've provided a fix here, see the logs after fix:

latin-panda added a commit that referenced this issue May 15, 2023
Stores the contact ID we want to load. Then as promises resolve, it checks that the contact we want to load is the same as from the data we had retrieved.
@latin-panda
Copy link
Contributor

Merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Fix something that isn't working as intended
Projects
Status: Done
Development

No branches or pull requests

2 participants