pulumi/sdk/go/common/workspace
Joe Duffy 24e72c9b51
Implement plugin download cancellation (#17621)
We use context.Background() when invoking plugin installation logic, and
generally do not propagate the context to all the various leaf I/O
operations performed in the course of installing plugins. As a result,
it is impossible to cancel them. Given that plugins can be 100MBs these
days, combined with the fact that we hook SIGINT and SIGTERM to block
them in attempt to provide a good user experience, this leads to
frustratingly long periods of time where you can't cancel an operation.
And, ironically, the time during which we're waiting for these plugins
to finish downloading is one of the few strictly safe points where
cancelling is fine, since generally no state-modifying operations are in
flight.

This change plumbs the true enclosing context to all of the places it
needs to go in order to make plugin installation cancellation work. Note
that I added `*WithContext` variants anytime dealing with a public
function for compatibility's sake. I will admit, I wish we could just
delete the other ones so that this is always an explicit decision.

This change also fixes a bug introduced in [a rather old pull request](
https://github.com/pulumi/pulumi/pull/5317/files), whereby we create
diagnostic events to tell the user a ^C has been registered -- but then
ignore the return values, never sending them to the engine!

I have included a test for cancellation. It is deliberately simple so it
can be deterministic (e.g., it doesn't test partial operations). I also
have not tested the myriad download sources, because it would make the
tests dependent on GitHub, GitLab, and other network sources that would
likely cause flakiness. Any/all feedback on how to improve coverage here
welcome, but it's better than nothing.

This fixes pulumi/pulumi#17594.

---------

Co-authored-by: Julien <julien@caffeine.lu>
2024-11-12 18:04:25 +00:00
..
config.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
creds.go Improve invalid credentials error message (#17541) 2024-10-11 19:23:35 +00:00
creds_test.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
loaders.go New deployment settings wizards and environment variables management comands (#16564) 2024-07-03 20:24:26 +00:00
loaders_test.go ignore unexpected types instead of erroring out (#14149) 2023-10-11 16:39:16 +00:00
paths.go Just use errors.Is instead of As and Is (#17250) 2024-09-12 23:52:26 +00:00
paths_test.go Don't search upwards for policy packs when determining required plugins (#16865) 2024-08-02 11:49:16 +00:00
plugins.go Implement plugin download cancellation (#17621) 2024-11-12 18:04:25 +00:00
plugins_install_nodejs_test.go ci: Use reduced smoke testing on Windows & macOS targets 2022-09-21 09:55:06 -07:00
plugins_install_python_test.go ci: Use reduced smoke testing on Windows & macOS targets 2022-09-21 09:55:06 -07:00
plugins_install_test.go Refactor: move plugin kind to apitype (#15946) 2024-04-25 17:30:30 +00:00
plugins_test.go Implement plugin download cancellation (#17621) 2024-11-12 18:04:25 +00:00
project.go Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00
project.json [sdk] add optional display name and tag fields to project templates (#14587) 2023-11-18 19:04:13 +00:00
project_test.go Preserve ordering when editing stack config. (#17452) 2024-10-02 13:31:10 +00:00
settings.go move pkg/workspace -> sdk/go/common/workspace 2020-03-18 14:35:53 -07:00
templates.go workspace.CopyTemplateFiles overwrite dirs with force (#17695) 2024-11-06 18:53:19 +00:00
templates_test.go workspace.CopyTemplateFiles overwrite dirs with force (#17695) 2024-11-06 18:53:19 +00:00
templates_zip.go Check zipped templates for `Pulumi.yaml` files (#17437) 2024-10-01 12:44:07 +00:00
templates_zip_test.go Check zipped templates for `Pulumi.yaml` files (#17437) 2024-10-01 12:44:07 +00:00
workspace.go all: Reformat with gofumpt 2023-03-03 09:00:24 -08:00