File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,14 @@ limitations under the License.
1717package utils
1818
1919import (
20+ "context"
21+ "fmt"
2022 "net"
2123 "net/url"
2224 "time"
2325
2426 "google.golang.org/grpc"
27+ "google.golang.org/grpc/connectivity"
2528)
2629
2730// Connect address by grpc
@@ -38,5 +41,19 @@ func Connect(address string) (*grpc.ClientConn, error) {
3841 }))
3942 }
4043
41- return grpc .Dial (address , dialOptions ... )
44+ conn , err := grpc .Dial (address , dialOptions ... )
45+ if err != nil {
46+ return nil , err
47+ }
48+
49+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
50+ defer cancel ()
51+ for {
52+ if ! conn .WaitForStateChange (ctx , conn .GetState ()) {
53+ return conn , fmt .Errorf ("Connection timed out" )
54+ }
55+ if conn .GetState () == connectivity .Ready {
56+ return conn , nil
57+ }
58+ }
4259}
You can’t perform that action at this time.
0 commit comments