Skip to content

Commit 5988bae

Browse files
author
Pasko Zdilar
committed
Invoke method in healthzServer when conn is Idle
1 parent 250bec2 commit 5988bae

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/internal/gateway/handlers.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"google.golang.org/grpc"
1212
"google.golang.org/grpc/connectivity"
1313
"google.golang.org/grpc/grpclog"
14+
"google.golang.org/protobuf/types/known/emptypb"
1415
)
1516

1617
// openAPIServer returns OpenAPI specification files located under "/openapiv2/"
@@ -59,6 +60,10 @@ func preflightHandler(w http.ResponseWriter, r *http.Request) {
5960
func healthzServer(conn *grpc.ClientConn) http.HandlerFunc {
6061
return func(w http.ResponseWriter, r *http.Request) {
6162
w.Header().Set("Content-Type", "text/plain")
63+
if s := conn.GetState(); s == connectivity.Idle {
64+
// Invoke method to move connection from Idle to Ready
65+
conn.Invoke(r.Context(), "/grpc.health.v1.Health/Check", &emptypb.Empty{}, &emptypb.Empty{})
66+
}
6267
if s := conn.GetState(); s != connectivity.Ready {
6368
http.Error(w, fmt.Sprintf("grpc server is %s", s), http.StatusBadGateway)
6469
return

0 commit comments

Comments
 (0)