mirror of
https://github.com/containers/gvisor-tap-vsock.git
synced 2025-10-08 10:10:12 +08:00
win-sshproxy.tid created before thread id is available
this commit fixes a potential race condition that prevented the tests to succeed when running in a github workflow. Basically the thread id was not actually available before writing it on the file, resulting in a thread id equals to 0 written in it. So, when the tests were trying to retrieve the thread id to use it to send the WM_QUIT signal, they failed. This patch adds a check on the thread id before writing it on the file. Now, if the thread id is 0, it keeps calling winquit to retrieve it. If, after 10 secs, there is no success it returns an error. Signed-off-by: lstocchi <lstocchi@redhat.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/containers/gvisor-tap-vsock/pkg/fs"
|
||||
"github.com/containers/gvisor-tap-vsock/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -98,13 +99,13 @@ func connectForward(ctx context.Context, bastion *Bastion) (CloseWriteConn, erro
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if bastionRetries > 2 || !sleep(ctx, 200*time.Millisecond) {
|
||||
if bastionRetries > 2 || !utils.Sleep(ctx, 200*time.Millisecond) {
|
||||
return nil, errors.Wrapf(err, "Couldn't reestablish ssh connection: %s", bastion.Host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !sleep(ctx, 200*time.Millisecond) {
|
||||
if !utils.Sleep(ctx, 200*time.Millisecond) {
|
||||
retries = 3
|
||||
}
|
||||
}
|
||||
@@ -173,7 +174,7 @@ func setupProxy(ctx context.Context, socketURI *url.URL, dest *url.URL, identity
|
||||
}
|
||||
return CreateBastion(dest, passphrase, identity, conn, connectFunc)
|
||||
}
|
||||
bastion, err := retry(ctx, createBastion, "Waiting for sshd")
|
||||
bastion, err := utils.Retry(ctx, createBastion, "Waiting for sshd")
|
||||
if err != nil {
|
||||
return &SSHForward{}, fmt.Errorf("setupProxy failed: %w", err)
|
||||
}
|
||||
@@ -183,37 +184,6 @@ func setupProxy(ctx context.Context, socketURI *url.URL, dest *url.URL, identity
|
||||
return &SSHForward{listener, bastion, socketURI}, nil
|
||||
}
|
||||
|
||||
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 acceptConnection(ctx context.Context, listener net.Listener, bastion *Bastion, socketURI *url.URL) error {
|
||||
con, err := listener.Accept()
|
||||
if err != nil {
|
||||
@@ -256,24 +226,3 @@ func forward(src io.ReadCloser, dest CloseWriteStream, complete *sync.WaitGroup)
|
||||
// Trigger an EOF on the other end
|
||||
_ = dest.CloseWrite()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user