Skip to content

Commit bc1b7c1

Browse files
authored
Allow storage_operation to gracefully cancel the LRO if an interrupt is received to prevent the orphaned LRO (#12995)
1 parent 31e852f commit bc1b7c1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mmv1/third_party/terraform/services/storage/storage_operation.go

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ func (w *StorageOperationWaiter) QueryOp() (interface{}, error) {
2323
if w == nil {
2424
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
2525
}
26+
27+
if w.Config.Context != nil {
28+
select {
29+
case <-w.Config.Context.Done():
30+
opCancelUrl := fmt.Sprintf("%s/cancel", w.SelfLink)
31+
_, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
32+
Config: w.Config,
33+
Method: "POST",
34+
RawURL: opCancelUrl,
35+
UserAgent: w.UserAgent,
36+
})
37+
if err != nil {
38+
return nil, fmt.Errorf("Error cancelling the LRO: %s", err)
39+
}
40+
return nil, fmt.Errorf("Interrupt recieved, operation cancelled")
41+
42+
default:
43+
// Default case is intentionally left empty, as per original logic.
44+
}
45+
}
46+
2647
// Returns the proper get.
2748
url := fmt.Sprintf(w.SelfLink)
2849

0 commit comments

Comments
 (0)