Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Log port wait errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov committed Jul 22, 2022
1 parent a2c1f92 commit a245b58
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ func main() {
log.Printf("Waiting on port %v...\n", port)

subCtx, cancel := context.WithTimeout(ctx, 60*time.Second)
network.WaitForLocalPort(subCtx, portNumber)
portErr := network.WaitForLocalPort(subCtx, portNumber)'
if portErr != nil {
log.Printf("Failed to wait fo port %v: %v\n", port, portErr)
}
cancel()
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"time"
)

func WaitForLocalPort(ctx context.Context, port int) {
func WaitForLocalPort(ctx context.Context, port int) error {
dialer := net.Dialer{
Timeout: 10 * time.Second,
}

var conn net.Conn
var err error

_ = retry.Do(
return retry.Do(
func() error {
conn, err = dialer.DialContext(ctx, "tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func TestEarlyExit(t *testing.T) {
defer cancel()

start := time.Now()
network.WaitForLocalPort(ctx, port)
err = network.WaitForLocalPort(ctx, port)
assert.Nil(t, err)
stop := time.Now()

assert.WithinDuration(t, stop, start, maxExpectedWaitTime)
Expand Down

0 comments on commit a245b58

Please sign in to comment.