-
Notifications
You must be signed in to change notification settings - Fork 51
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
win-sshproxy.tid created before thread id is available #433
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package utils | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const maxRetries = 60 | ||
const initialBackoff = 100 * time.Millisecond | ||
|
||
func Retry[T comparable](ctx context.Context, retryFunc func() (T, error), retryMsg string) (T, error) { | ||
var ( | ||
returnVal T | ||
err error | ||
) | ||
|
||
backoff := initialBackoff | ||
|
||
loop: | ||
for i := 0; i < maxRetries; i++ { | ||
select { | ||
case <-ctx.Done(): | ||
break loop | ||
default: | ||
// proceed | ||
} | ||
|
||
returnVal, err = retryFunc() | ||
if err == nil { | ||
return returnVal, nil | ||
} | ||
logrus.Debugf("%s (%s)", retryMsg, backoff) | ||
Sleep(ctx, backoff) | ||
backoff = backOff(backoff) | ||
} | ||
return returnVal, fmt.Errorf("timeout: %w", err) | ||
} | ||
|
||
func backOff(delay time.Duration) time.Duration { | ||
if delay == 0 { | ||
delay = 5 * time.Millisecond | ||
} else { | ||
delay *= 2 | ||
} | ||
if delay > time.Second { | ||
delay = time.Second | ||
} | ||
return delay | ||
} | ||
|
||
func Sleep(ctx context.Context, wait time.Duration) bool { | ||
select { | ||
case <-ctx.Done(): | ||
return false | ||
case <-time.After(wait): | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This will add a slight delay during win-ssh-proxy startup, do you expect this delay to be problematic in typical use?
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.
IMO no but I have a limited knowledge of its usage. Locally, and for the stuff I do, I didn't even notice.
Maybe it would be noticeable with low resources machine but better to slow it a bit at startup and be sure everything works fine, no?
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.
I expect it won't be noticeable. However, if this was noticeable, this would have an impact on
podman machine start
startup time, which can be problematic.Since the thread id is only needed when one wants to stop the podman machine VM, an alternative would be to try to do the waiting and writing of the thread id in a go routine to avoid the blocking.
However, podman would need to be ready for that, and retry reading the file if it's missing, which is not the case at the moment.
With all that said, the current approach should be good enough for now.