Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on remote connection errors #530

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions provider/pkg/provider/remote/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Copy link
Member

@mjeffryes mjeffryes Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ok && err == nil {
// It's important to check both `ok` and `err` as sometimes `err` will be nil when `ok` is false, such as when the context is cancelled
if ok && err == nil {

return data.(T), nil
}

var t T
if err == nil {
err = ctx.Err()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
err = ctx.Err()
// `err` is nil but ok was false, use the err reported from the context.
err = ctx.Err()

}
return t, err
}

Expand Down