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

[$multiWatch] simplified the code and fixed a race condition #3685

Merged
merged 3 commits into from
May 1, 2015

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Apr 24, 2015

While debugging an issue with @w33ble we noticed a race condition in $multiWatch.

When $multiWatch triggered the change handler, the values being passed in did not match the actual values defined on scope. This was happening because a child $scope modifies the value being watched in the same digest cycle that the parent watcher triggers. Generally data flows top down but the filter bar is says "screw the trickle down effect!", which drew out this bug.

This test was added to simulate the necessary conditions.

While considering solutions, I learned that $watch handlers are always executed in order, so I was able to simplify the logic and have the handler execute in exactly the same position as a normal would (as opposed to using $scope.$evalAsync)

@spalger spalger added the review label Apr 24, 2015
@spalger spalger force-pushed the fix/multiWatchRaceCondition branch from 92c6374 to fb0282a Compare April 24, 2015 22:48
@@ -34,80 +34,70 @@ define(function (require) {
* @param {boolean} deep - should the watchers be created as deep watchers?
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this from the docblock

@spalger spalger added the v4.1.0 label Apr 24, 2015
@spalger spalger force-pushed the fix/multiWatchRaceCondition branch from fb0282a to 0759c97 Compare April 25, 2015 00:39
@spalger spalger mentioned this pull request Apr 27, 2015
5 tasks
@w33ble
Copy link
Contributor

w33ble commented Apr 30, 2015

This seems fine, but I'd like to spend some more time with it, as well as apply it against #2518 since that's how I found the original issue. In the meantime, and since this should probably have a couple sets of eyes on it anyway, I'm going to send this to @lukasolson for now.

Lukas, please assign back to me after you've had a chance to check it out.

@w33ble w33ble assigned lukasolson and unassigned w33ble Apr 30, 2015
@lukasolson
Copy link
Member

I've played around with a couple areas of the application that use $watchMulti and they seem to work fine after this change, and I've taken a look at the code and it looks good. Passing it back to @w33ble.

@lukasolson lukasolson assigned w33ble and unassigned lukasolson Apr 30, 2015
@w33ble
Copy link
Contributor

w33ble commented May 1, 2015

Looks good against #2518, and I can't find any issues with it.

merge

w33ble added a commit that referenced this pull request May 1, 2015
[$multiWatch] simplified the code and fixed a race condition
@w33ble w33ble merged commit f515008 into elastic:master May 1, 2015
@spalger spalger deleted the fix/multiWatchRaceCondition branch July 31, 2015 04:56
alexwizp added a commit to alexwizp/kibana that referenced this pull request Jul 10, 2024
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.

3 participants