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

Commit

Permalink
retry connect for flakey port-forward connections
Browse files Browse the repository at this point in the history
Signed-off-by: Darren Shepherd <darren@acorn.io>
  • Loading branch information
ibuildthecloud committed Oct 25, 2022
1 parent ed8d585 commit c2e5499
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/portforwarder/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package portforwarder

import (
"context"
"fmt"
"net"
"net/url"
"strconv"
"time"

"github.com/acorn-io/acorn/pkg/k8schannel"
corev1 "k8s.io/api/core/v1"
Expand All @@ -18,11 +20,18 @@ type WebSocketDialer struct {
}

func (w *WebSocketDialer) DialContext(ctx context.Context, address string) (net.Conn, error) {
conn, err := w.dialer.DialContext(ctx, w.url, nil)
if err != nil {
return nil, err
for i := 0; ; i++ {
// It seems to be that port forwards are very unreliable on connect
conn, err := w.dialer.DialContext(ctx, w.url, nil)
if err != nil {
if i < 5 {
time.Sleep(100 * time.Millisecond)
continue
}
return nil, fmt.Errorf("failed to connect: %w", err)
}
return conn.ForStream(0), nil
}
return conn.ForStream(0), nil
}

func NewWebSocketDialerForURL(cfg *rest.Config, url *url.URL) (*WebSocketDialer, error) {
Expand Down

0 comments on commit c2e5499

Please sign in to comment.