-
Notifications
You must be signed in to change notification settings - Fork 27
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
base: master
Are you sure you want to change the base?
Conversation
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.
PR is now waiting for a maintainer to run the acceptance tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! This looks reasonable to me, though it would be nice to add some comments and a test case. I don't know how difficult it would be to simulate a cancellation in test?
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = ctx.Err() | |
// `err` is nil but ok was false, use the err reported from the context. | |
err = ctx.Err() |
There was a panic in
remote.dialWithRetry()
on the context cancellation, e.g. when the timeout specified bypulumi.Timeouts()
passed toremote.NewCommand()
exceeded.retry.Until()
when the context is cancelled returns:ok = false, data = nil, err = nil
; so if we try to castdata
toT
, we get panic:We can cast
data
toT
inremote.dialWithRetry()
, not only whenerr
returned fromretry.Until()
isnil
, but also whenok
istrue
.