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

Conversation

waketheashes
Copy link

There was a panic in remote.dialWithRetry() on the context cancellation, e.g. when the timeout 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.

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.
Copy link

github-actions bot commented Sep 5, 2024

PR is now waiting for a maintainer to run the acceptance tests.
Note for the maintainer: To run the acceptance tests, please comment /run-acceptance-tests on the PR

Copy link
Member

@mjeffryes mjeffryes left a 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 {
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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants