pulumi/pkg/backend
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
..
display Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00
diy Persist metadata about snapshot integrity errors (#17291) 2024-11-06 17:35:27 +00:00
filestate Rename filestate to DIY (#15314) 2024-01-30 15:53:10 +00:00
httpstate stop the token source loop correctly on 403 errors (#17714) 2024-11-08 08:31:50 +00:00
state [breaking] Changing the version of go.mod in sdk / pkg to be v3 2021-04-14 19:32:18 +01:00
apply.go Fix rendering of output events in rendering update diffs (#17029) 2024-08-27 18:37:03 +00:00
apply_test.go Make `engine.NewEvent` type safe (#14590) 2023-11-16 16:54:03 +00:00
backend.go Pass ESC Environments on stack update (#17665) 2024-11-07 18:54:46 +00:00
backend_test.go Allow anything in resource names (#14107) 2023-11-20 08:59:00 +00:00
cancellation_scope.go Implement plugin download cancellation (#17621) 2024-11-12 18:04:25 +00:00
doc.go Document Go packages (#6009) 2021-01-11 11:07:59 -07:00
errors.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
inmemoryPersister.go Revert "Revert "Run integration tests and dev builds with race detection" (#15998)" (#16148) 2024-05-09 16:15:41 +00:00
login_manager.go Add LoginManager to backend package (#17199) 2024-09-10 09:04:49 +00:00
mock.go Respect existing stack configuration when initialising secret managers (#17465) 2024-10-03 15:40:39 +00:00
policypack.go Replace `result.Result` with native errors (#17044) 2024-08-22 14:39:59 +00:00
query.go Enable goheader rule and add missing license headers (#15473) 2024-09-09 12:05:45 +00:00
snapshot.go Persist metadata about snapshot integrity errors (#17291) 2024-11-06 17:35:27 +00:00
snapshot_test.go Persist metadata about snapshot integrity errors (#17291) 2024-11-06 17:35:27 +00:00
stack.go Allow `Backend`s to define `DefaultSecretManager`s (#17370) 2024-09-26 08:52:24 +00:00
updates.go [cli] Include config from ESC in `pulumi config` (#14560) 2023-11-21 10:44:45 +00:00
watch.go Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00