Skip to content

The gzip resource should support context cancellation #835

@purpleidea

Description

@purpleidea

Background:

We have a resource API that lets use build resource to accomplish tasks that we describe in mcl. The main "work doing" method is CheckApply. For the "gzip" resource (which gzip's a file) that is here:

https://github.com/purpleidea/mgmt/blob/master/engine/resources/gzip.go#L281

Golang Context:

In golang there's no way to "kill" a running task/process/goroutine/etc like you would with the kernel. Instead the "context" package provides a special handle which you pass in before you run something. If you want that thing to end early, you cancel that handle which the caller is hopefully monitoring, which lets it decide to voluntarily end early.

Task:

The gzip resource doesn't use the ctx. This patch should ensure it gets used, in particular around whatever the longest/slowest operation that you might encounter.

Steps:

  1. First test out the gzip resource to make sure you understand how it works.
  2. Next determine where the context needs to get used.
  3. Lastly implement this.
  4. Bonus: test this out if you can find a simple enough way to write a test in pure golang.

Gotcha:

We cancel typically because the user pressed ^C and wanted to shutdown early. This is allowed, but what is not allowed is leaving the system in a partial state which we might not know to be safe. For example, if we've written half of the gzip file and then we exit, but we leave it on disk where the user asked, we might not realize that it's only half written. So it's crucial that if we do error or shutdown early that any partially written data is removed. You should check this is the case for any error scenarios as well.

Extra:

Don't use any LLM's as this won't help you learn!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions