Extract waitForGvProxy into shared utility function

Signed-off-by: Arthur Sengileyev <arthur.sengileyev@gmail.com>
This commit is contained in:
Arthur Sengileyev
2024-02-16 18:15:36 +02:00
parent d5a17ad9a0
commit 49400ecce1
2 changed files with 17 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"net"
"os"
"path/filepath"
"time"
@ -94,3 +95,18 @@ func DialSocketWithBackoffsAndProcCheck(
}
return nil, err
}
// WaitForSocketWithBackoffs attempts to discover listening socket in maxBackoffs attempts
func WaitForSocketWithBackoffs(maxBackoffs int, backoff time.Duration, socketPath string, name string) error {
backoffWait := backoff
logrus.Debugf("checking that %q socket is ready", name)
for i := 0; i < maxBackoffs; i++ {
_, err := os.Stat(socketPath)
if err == nil {
return nil
}
time.Sleep(backoffWait)
backoffWait *= 2
}
return fmt.Errorf("unable to connect to %q socket at %q", name, socketPath)
}