mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
use correct context for communicator.Retry
The timeout for a provisioner is expected to only apply to the initial connection. Keep the context for the communicator.Retry separate from the global cancellation context.
This commit is contained in:
parent
38e6309f03
commit
9b4b5f2a72
@ -312,11 +312,11 @@ func applyFn(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Wait and retry until we establish the connection
|
// Wait and retry until we establish the connection
|
||||||
err = communicator.Retry(ctx, func() error {
|
err = communicator.Retry(retryCtx, func() error {
|
||||||
return comm.Connect(o)
|
return comm.Connect(o)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -48,9 +48,6 @@ func applyFn(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// Get the source
|
// Get the source
|
||||||
src, deleteSource, err := getSrc(data)
|
src, deleteSource, err := getSrc(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -99,8 +96,11 @@ func getSrc(data *schema.ResourceData) (string, bool, error) {
|
|||||||
|
|
||||||
// copyFiles is used to copy the files from a source to a destination
|
// copyFiles is used to copy the files from a source to a destination
|
||||||
func copyFiles(ctx context.Context, comm communicator.Communicator, src, dst string) error {
|
func copyFiles(ctx context.Context, comm communicator.Communicator, src, dst string) error {
|
||||||
|
retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
// Wait and retry until we establish the connection
|
// Wait and retry until we establish the connection
|
||||||
err := communicator.Retry(ctx, func() error {
|
err := communicator.Retry(retryCtx, func() error {
|
||||||
return comm.Connect(nil)
|
return comm.Connect(nil)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -231,10 +231,10 @@ func applyFn(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err = communicator.Retry(ctx, func() error {
|
err = communicator.Retry(retryCtx, func() error {
|
||||||
return comm.Connect(o)
|
return comm.Connect(o)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -157,20 +157,23 @@ func runScripts(
|
|||||||
comm communicator.Communicator,
|
comm communicator.Communicator,
|
||||||
scripts []io.ReadCloser) error {
|
scripts []io.ReadCloser) error {
|
||||||
|
|
||||||
// Wait for the context to end and then disconnect
|
retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
||||||
go func() {
|
defer cancel()
|
||||||
<-ctx.Done()
|
|
||||||
comm.Disconnect()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Wait and retry until we establish the connection
|
// Wait and retry until we establish the connection
|
||||||
err := communicator.Retry(ctx, func() error {
|
err := communicator.Retry(retryCtx, func() error {
|
||||||
return comm.Connect(o)
|
return comm.Connect(o)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the context to end and then disconnect
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
comm.Disconnect()
|
||||||
|
}()
|
||||||
|
|
||||||
for _, script := range scripts {
|
for _, script := range scripts {
|
||||||
var cmd *remote.Cmd
|
var cmd *remote.Cmd
|
||||||
|
|
||||||
|
@ -131,17 +131,11 @@ func applyFn(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancelFunc := context.WithTimeout(ctx, comm.Timeout())
|
retryCtx, cancel := context.WithTimeout(ctx, comm.Timeout())
|
||||||
defer cancelFunc()
|
defer cancel()
|
||||||
|
|
||||||
// Wait for the context to end and then disconnect
|
|
||||||
go func() {
|
|
||||||
<-ctx.Done()
|
|
||||||
comm.Disconnect()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Wait and retry until we establish the connection
|
// Wait and retry until we establish the connection
|
||||||
err = communicator.Retry(ctx, func() error {
|
err = communicator.Retry(retryCtx, func() error {
|
||||||
return comm.Connect(o)
|
return comm.Connect(o)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -149,6 +143,12 @@ func applyFn(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the context to end and then disconnect
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
comm.Disconnect()
|
||||||
|
}()
|
||||||
|
|
||||||
var src, dst string
|
var src, dst string
|
||||||
|
|
||||||
o.Output("Provisioning with Salt...")
|
o.Output("Provisioning with Salt...")
|
||||||
|
Loading…
Reference in New Issue
Block a user