Skip to content

Commit aa54b91

Browse files
winkingturtle-vmwgeofffranks
authored andcommitted
Return connection when Connected
- [X] Read the [Contributing document](../blob/-/.github/CONTRIBUTING.md). Summary --------------- Context: Context: grpc/grpc-go#7029 Wait for status changed and return when connection is connected. Since DialContext has been removed, it's a bit unclear what needed to happen for connection to be ready for use. This code will bring back partial implementation of DialContext so that connection is ready. Backward Compatibility --------------- Breaking Change? **No**
1 parent 2c9b31c commit aa54b91

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

locket_client.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"code.cloudfoundry.org/locket/models"
1010
"code.cloudfoundry.org/tlsconfig"
1111
"google.golang.org/grpc"
12+
"google.golang.org/grpc/connectivity"
1213
"google.golang.org/grpc/credentials"
1314
"google.golang.org/grpc/keepalive"
1415
)
@@ -53,6 +54,8 @@ func newClientInternal(logger lager.Logger, config ClientLocketConfig, skipCertV
5354
// return a list of addresses. We will also need to add a new NewClient
5455
// method that accepts a dialer in order to mock the ipsec (blocking) issue
5556
// we ran into in https://www.pivotaltracker.com/story/show/158104990
57+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
58+
defer cancel()
5659
conn, err := grpc.NewClient(config.LocketAddress,
5760
grpc.WithTransportCredentials(credentials.NewTLS(locketTLSConfig)),
5861
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
@@ -67,5 +70,17 @@ func newClientInternal(logger lager.Logger, config ClientLocketConfig, skipCertV
6770
if err != nil {
6871
return nil, err
6972
}
70-
return models.NewLocketClient(conn), nil
73+
74+
for {
75+
s := conn.GetState()
76+
if s == connectivity.Idle {
77+
conn.Connect()
78+
}
79+
if s == connectivity.Ready {
80+
return models.NewLocketClient(conn), nil
81+
}
82+
if !conn.WaitForStateChange(ctx, s) {
83+
return nil, ctx.Err()
84+
}
85+
}
7186
}

0 commit comments

Comments
 (0)