From 9c0182f301b061303ff5440b75568203411cd023 Mon Sep 17 00:00:00 2001 From: waketheashes Date: Thu, 5 Sep 2024 19:29:02 +0300 Subject: [PATCH] Fix panic on remote connection errors There was a panic in remote.dialWithRetry() on context cancellation, e.g. when timeout that was specified by pulumi.Timeouts() passed to remote.NewCommand() exceeded. retry.Until() when the context is cancelled returns: ok = false, data = nil, err = nil; so if we try to cast data to T, we get panic: > interface conversion: interface {} is nil, not T We can cast data to T in remote.dialWithRetry(), not only when err returned from retry.Until() is nil, but also when ok is true. --- provider/pkg/provider/remote/connection.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/provider/pkg/provider/remote/connection.go b/provider/pkg/provider/remote/connection.go index f56448e4..32d11f6f 100644 --- a/provider/pkg/provider/remote/connection.go +++ b/provider/pkg/provider/remote/connection.go @@ -122,7 +122,7 @@ func (con *connectionBase) SShConfig() (*ssh.ClientConfig, error) { func dialWithRetry[T any](ctx context.Context, msg string, maxAttempts int, f func() (T, error)) (T, error) { var userError error - _, data, err := retry.Until(ctx, retry.Acceptor{ + ok, data, err := retry.Until(ctx, retry.Acceptor{ Accept: func(try int, _ time.Duration) (bool, any, error) { var result T result, userError = f() @@ -145,11 +145,14 @@ func dialWithRetry[T any](ctx context.Context, msg string, maxAttempts int, f fu return false, nil, nil }, }) - if err == nil { + if ok && err == nil { return data.(T), nil } var t T + if err == nil { + err = ctx.Err() + } return t, err }