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 monitor/scheduler race condition. #1186

Merged
merged 1 commit into from
Oct 18, 2017

Conversation

baldwinn860
Copy link
Contributor

There was a race condition that caused the scheduler to update robot
tasks with incomplete information. Managers would monitor for changes
inside a goroutine that would compete with the update logic of the data
owner. All initial data would be read in at once, but still in another
thread, which caused the scheduler to update without full knowledge of
entity state, this would cause extraneous tasks to get spawned every
time robot was restarted.

The fix is to initialize the owner's data with a non monitoring search
in the main thread before spawning goroutines to continue monitoring
updates. This ensures we have the complete initial information prior to
the first update. The other changes ensure that the monitoring updates
do not append extraneous entries.

There was a race condition that caused the scheduler to update robot
tasks with incomplete information. Managers would monitor for changes
inside a goroutine that would compete with the update logic of the data
owner. All initial data would be read in at once, but still in another
thread, which caused the scheduler to update without full knowledge of
entity state, this would cause extraneous tasks to get spawned every
time robot was restarted.

The fix is to initialize the owner's data with a non monitoring search
in the main thread before spawning goroutines to continue monitoring
updates. This ensures we have the complete initial information prior to
the first update.
if managers.Job != nil {
crash.Go(func() { managers.Job.SearchDevices(ctx, all, owner.updateDevice) })
crash.Go(func() { managers.Job.SearchWorkers(ctx, all, owner.updateWorker) })
if err := managers.Job.SearchDevices(ctx, initial, owner.updateDevice); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little upset that I can't find a way to refactor this into something more compact without resorting to reflection. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, me too, I had written like three different solutions but this was by far the most succinct, all the rest kind of exploded into lots of code changes.

@baldwinn860 baldwinn860 merged commit db7975c into google:master Oct 18, 2017
@baldwinn860 baldwinn860 deleted the fix_scheduler branch October 18, 2017 17:30
purvisa-at-google-com pushed a commit that referenced this pull request Sep 29, 2022
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.

None yet

2 participants