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.
17
17
package utils
18
18
19
19
import (
20
+ "context"
21
+ "fmt"
20
22
"net"
21
23
"net/url"
22
24
"time"
23
25
24
26
"google.golang.org/grpc"
27
+ "google.golang.org/grpc/connectivity"
25
28
)
26
29
27
30
// Connect address by grpc
@@ -38,5 +41,19 @@ func Connect(address string) (*grpc.ClientConn, error) {
38
41
}))
39
42
}
40
43
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
+ }
42
59
}
You can’t perform that action at this time.
0 commit comments