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

Disable keep alive for gRPC channel #481

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions golang/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
validator "github.com/go-playground/validator/v10"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/keepalive"
)

var (
Expand Down Expand Up @@ -107,13 +106,6 @@ func (c *clientConn) Close() error {
}

func (c *clientConn) dialSetupOpts(dopts ...grpc.DialOption) (opts []grpc.DialOption, err error) {
if c.opts.DialKeepAliveTime > 0 {
opts = append(opts, grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: c.opts.DialKeepAliveTime,
Timeout: c.opts.DialKeepAliveTimeout,
PermitWithoutStream: c.opts.PermitWithoutStream,
}))
}
opts = append(opts, dopts...)
if c.creds != nil {
opts = append(opts, grpc.WithTransportCredentials(c.creds))
Expand Down
38 changes: 0 additions & 38 deletions golang/conn_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ type connOptions struct {
// other operations that do not have an explicit context.
Context context.Context

// DialKeepAliveTime is the time after which client pings the server to see if
// transport is alive.
DialKeepAliveTime time.Duration

// DialKeepAliveTimeout is the time that the client waits for a response for the
// keep-alive probe. If the response is not received in this time, the connection is closed.
DialKeepAliveTimeout time.Duration

// PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs).
PermitWithoutStream bool

// DialTimeout is the timeout for failing to establish a connection.
DialTimeout time.Duration

Expand All @@ -79,7 +68,6 @@ var defaultConnOptions = connOptions{
RootCAs: x509.NewCertPool(),
InsecureSkipVerify: true,
},
DialKeepAliveTime: time.Second * 30,
Logger: zaplog.New(),
}

Expand Down Expand Up @@ -157,32 +145,6 @@ func WithContext(ctx context.Context) ConnOption {
})
}

// WithDialKeepAliveTime returns a ConnOption that sets DialKeepAliveTime for grpc.DialContext.
// DialKeepAliveTime is the time after which client pings the server to see if transport is alive.
func WithDialKeepAliveTime(d time.Duration) ConnOption {
return newFuncConnOption(func(o *connOptions) {
o.DialKeepAliveTime = d
})
}

// WithDialKeepAliveTimeout returns a ConnOption that sets DialKeepAliveTimeout for grpc.DialContext.
// DialKeepAliveTimeout is the time that the client waits for a response for the keep-alive probe.
// If the response is not received in this time, the connection is closed.
func WithDialKeepAliveTimeout(d time.Duration) ConnOption {
return newFuncConnOption(func(o *connOptions) {
o.DialKeepAliveTimeout = d
})
}

// WithPermitWithoutStream returns a ConnOption that sets PermitWithoutStream for grpc.DialContext.
// PermitWithoutStream when set will allow client to send keepalive pings to server without any
// active streams(RPCs).
func WithPermitWithoutStream(permit bool) ConnOption {
return newFuncConnOption(func(o *connOptions) {
o.PermitWithoutStream = permit
})
}

func WithZapLogger(logger *zap.Logger) ConnOption {
return newFuncConnOption(func(o *connOptions) {
o.Logger = logger
Expand Down