Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More reliable connections #29

Merged
merged 1 commit into from
Jan 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
More reliable connections
Signed-off-by: Luis Pabón <luis@portworx.com>
lpabon committed Jan 19, 2018
commit 1f2b6aa17b08c309e47487093a12c3319fab01d4
19 changes: 18 additions & 1 deletion utils/grpcutil.go
Original file line number Diff line number Diff line change
@@ -17,11 +17,14 @@ limitations under the License.
package utils

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

"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

// Connect address by grpc
@@ -38,5 +41,19 @@ func Connect(address string) (*grpc.ClientConn, error) {
}))
}

return grpc.Dial(address, dialOptions...)
conn, err := grpc.Dial(address, dialOptions...)
if err != nil {
return nil, err
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
for {
if !conn.WaitForStateChange(ctx, conn.GetState()) {
return conn, fmt.Errorf("Connection timed out")
}
if conn.GetState() == connectivity.Ready {
return conn, nil
}
}
}