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: asoctl deadlock #4475

Merged
merged 5 commits into from
Dec 5, 2024
Merged

Fix: asoctl deadlock #4475

merged 5 commits into from
Dec 5, 2024

Conversation

theunrepentantgeek
Copy link
Member

What this PR does

Fixes an ASO deadlock introduced in #4452.

The immediate cause of the deadlock was an omitted call to Completed(1) when collating import errors, leaving the progress bar incomplete.

However, this coupling between the progress bar and the importer isn't ideal, and leaves the door open for addition problems in the future. To avoid this, I've made two additional changes.

  • Introduced a watchdog to keep track of inflight resources, to monitor the import, and to shut things down when everything is done
  • Refactored construction of the data flow graph into separate sections that can be more easily reasoned about independently.

Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

Partial review, I should keep packing rather than getting sidetracked by fun concurrency fixes! Looks good so far though!

v2/cmd/asoctl/go.mod Show resolved Hide resolved
case rsrc, ok := <-resources:
if !ok {
// Channel closed
running = false
Copy link
Member

Choose a reason for hiding this comment

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

It'd be clearer to label the for loop and use a labelled break here (assuming I haven't missed some other stuff that needs to happen after the select).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Collaborator

@super-harsh super-harsh left a comment

Choose a reason for hiding this comment

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

Minor comments. Just double checking on a few things, feel free to ignore if you think the comments are irrelevant.

Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

Looks nice!

}

// Close the channel when we're done, so that workers shut down too
close(uniqueResources)
Copy link
Member

Choose a reason for hiding this comment

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

Defer this at the top of the goroutine func to ensure it's closed even in the case of panics?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 297 to 298
ri.reporter.Completed(1)
watchdog.stopped()
Copy link
Member

Choose a reason for hiding this comment

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

I'd put these into a method on ResourceImporter and then call it from both the success and error workers. Tying them together makes it harder to forget to do it in one place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@theunrepentantgeek theunrepentantgeek added this pull request to the merge queue Dec 5, 2024
Merged via the queue into main with commit 3e3f11a Dec 5, 2024
7 checks passed
@theunrepentantgeek theunrepentantgeek deleted the improve/asoctl-channels branch December 5, 2024 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
Status: Ready for Release
Development

Successfully merging this pull request may close these issues.

3 participants