Skip to content

Fix potential race condition if worker disconnects - #266

Merged
allada merged 1 commit into
mainfrom
fix-worker-cleanup-race
Sep 11, 2023
Merged

allada merged 1 commit into
mainfrom
fix-worker-cleanup-race

Conversation

@allada

@allada allada commented Sep 10, 2023 •

Copy link
Copy Markdown
Contributor

In the event the worker disconnects from the scheduler, we now wait until all actions are killed before we attempt to reconnect to the scheduler. This prevents a race condition where the scheduler does not know about an action the worker is doing resulting in a potential of the scheduler sending the same action to the worker that it has not cleaned up yet.

fixes #246


This change is Reviewable

@allada allada left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

+@chrisstaite-menlo

Reviewable status: 0 of 3 files reviewed, all discussions resolved (waiting on @chrisstaite-menlo)

@allada
allada force-pushed the fix-worker-cleanup-race branch 2 times, most recently from ff3d8fd to 30f3240 Compare September 10, 2023 23:59
@allada
allada force-pushed the fix-worker-cleanup-race branch 13 times, most recently from 64e845e to 1de293f Compare September 11, 2023 05:01

@chrisstaite-menlo chrisstaite-menlo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @allada)


cas/worker/local_worker.rs line 487 at r1 (raw file):

                        (sleep_fn_pin)(Duration::from_secs_f32(sleep_duration)).await;
                    }
                    if inner.actions_in_transit.load(Ordering::Acquire) != 0 {

Might be a good use for a label to perform a for-else rather than check the value again.


cas/worker/running_actions_manager.rs line 1164 at r1 (raw file):

    fn cleanup_action(&self, action_id: &ActionId) -> Result<(), Error> {
        println!("cleanup_action triggered");

Debug value


cas/worker/tests/running_actions_manager_test.rs line 140 at r1 (raw file):

#[cfg(test)]
mod running_actions_manager_tests {
    use std::sync::atomic::AtomicBool;

Weird to place this in the mod?

In the event the worker disconnects from the scheduler, we now
wait until all actions are killed before we attempt to reconnect
to the scheduler. This prevents a race condition where the
scheduler does not know about an action the worker is doing
resulting in a potential of the scheduler sending the same
action to the worker that it has not cleaned up yet.

fixes #246
@allada
allada force-pushed the fix-worker-cleanup-race branch from 1de293f to cd3c413 Compare September 11, 2023 14:35

@allada allada left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @chrisstaite-menlo)


cas/worker/local_worker.rs line 487 at r1 (raw file):

Previously, chrisstaite-menlo (Chris Staite) wrote…

Might be a good use for a label to perform a for-else rather than check the value again.

Done.


cas/worker/running_actions_manager.rs line 1164 at r1 (raw file):

Previously, chrisstaite-menlo (Chris Staite) wrote…

Debug value

Done.


cas/worker/tests/running_actions_manager_test.rs line 140 at r1 (raw file):

Previously, chrisstaite-menlo (Chris Staite) wrote…

Weird to place this in the mod?

Done. My editor did this.

@chrisstaite-menlo chrisstaite-menlo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r2.
Reviewable status: 2 of 3 files reviewed, all discussions resolved (waiting on @allada)


cas/worker/tests/running_actions_manager_test.rs line 140 at r1 (raw file):

Previously, allada (Nathan (Blaise) Bruer) wrote…

Done. My editor did this.

Mine did the same for somewhere else. They're so helpful... sometimes.

@chrisstaite-menlo chrisstaite-menlo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @allada)

@allada
allada merged commit b871a90 into main Sep 11, 2023
@allada
allada deleted the fix-worker-cleanup-race branch September 11, 2023 19:51
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.

If a worker is killed, stale work directories exist

2 participants