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

Fixing Worker Pool race condition for assignments #875

Merged
merged 3 commits into from
Aug 1, 2022

Conversation

JackUrb
Copy link
Contributor

@JackUrb JackUrb commented Aug 1, 2022

Overview

An awkward race condition existed that allowed Mephisto to attempt to launch an Assignment before the WorkerPool had actually registered all of the Agents for that Assignment into its local self.agents dictionary. This could occur if the last _assign_unit_to_agent thread for an Assignment ran during the await-wrapped get_init_data_for_agent call of the second to last _assign_unit_to_agent for the same Assignment. Then the second to last thread would resume during the last call's get_init_data_for_agent. The outcome is that loop.run_in_executor(None, assignment.get_agents) would return all the Agents, but one wouldn't yet be added to the WorkerPool's tracking.

Fix Details

Rather than just using the None check for the Assignment.get_agents() call, we do a get check for the WorkerPool's agents as well, then bail early if any haven't been set.

Testing:

Automated testing

Would be nice if there was an asyncio testing library that intentionally took unusual routes (like by adding asyncio.sleep of random durations to all await calls) to catch this kind of thing sooner...

@JackUrb JackUrb requested a review from chiehminwei August 1, 2022 16:12
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 1, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #875 (3e5af73) into main (ebac0c8) will increase coverage by 0.02%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##             main     #875      +/-   ##
==========================================
+ Coverage   64.60%   64.62%   +0.02%     
==========================================
  Files         108      108              
  Lines        9301     9307       +6     
==========================================
+ Hits         6009     6015       +6     
  Misses       3292     3292              
Impacted Files Coverage Δ
mephisto/operations/worker_pool.py 80.73% <50.00%> (-0.42%) ⬇️
mephisto/data_model/unit.py 77.59% <0.00%> (-0.55%) ⬇️
mephisto/utils/metrics.py 29.10% <0.00%> (-0.22%) ⬇️
...ractions/blueprints/mixins/screen_task_required.py 74.74% <0.00%> (+0.25%) ⬆️
mephisto/abstractions/architects/mock_architect.py 90.84% <0.00%> (+2.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ebac0c8...3e5af73. Read the comment docs.

Copy link
Contributor

@chiehminwei chiehminwei left a comment

Choose a reason for hiding this comment

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

Thanks so much for the fix! LGTM

@JackUrb JackUrb merged commit 889496b into main Aug 1, 2022
@JackUrb JackUrb deleted the worker-pool-assignment-race branch August 1, 2022 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants