Skip to content

Commit 312be59

Browse files
authored
Provide custom gRPC dialer to override default proxy dialer (#2419)
Signed-off-by: Anshul Pundir <[email protected]>
1 parent 4f12bf7 commit 312be59

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

connectionbroker/broker.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
package connectionbroker
55

66
import (
7+
"net"
78
"sync"
9+
"time"
810

911
"github.com/docker/swarmkit/api"
1012
"github.com/docker/swarmkit/remotes"
@@ -60,9 +62,14 @@ func (b *Broker) SelectRemote(dialOpts ...grpc.DialOption) (*Conn, error) {
6062
return nil, err
6163
}
6264

65+
// gRPC dialer connects to proxy first. Provide a custom dialer here avoid that.
66+
// TODO(anshul) Add an option to configure this.
6367
dialOpts = append(dialOpts,
6468
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor),
65-
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor))
69+
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor),
70+
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
71+
return net.DialTimeout("tcp", addr, timeout)
72+
}))
6673

6774
cc, err := grpc.Dial(peer.Addr, dialOpts...)
6875
if err != nil {

manager/state/raft/transport/transport.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package transport
44

55
import (
6+
"net"
67
"sync"
78
"time"
89

@@ -348,6 +349,13 @@ func (t *Transport) dial(addr string) (*grpc.ClientConn, error) {
348349
grpcOptions = append(grpcOptions, grpc.WithTimeout(t.config.SendTimeout))
349350
}
350351

352+
// gRPC dialer connects to proxy first. Provide a custom dialer here avoid that.
353+
// TODO(anshul) Add an option to configure this.
354+
grpcOptions = append(grpcOptions,
355+
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
356+
return net.DialTimeout("tcp", addr, timeout)
357+
}))
358+
351359
cc, err := grpc.Dial(addr, grpcOptions...)
352360
if err != nil {
353361
return nil, err

0 commit comments

Comments
 (0)