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

Avoid 'transport closing' errors on client side #299

Merged
merged 1 commit into from
Jul 11, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ _testmain.go
*.exe
*.test
*.prof
bblfshd
bblfshctl
28 changes: 25 additions & 3 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"sync"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"

"github.com/opentracing/opentracing-go"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"

"github.com/bblfsh/bblfshd/daemon/protocol"
"github.com/bblfsh/bblfshd/runtime"
Expand All @@ -21,6 +23,18 @@ import (
protocol1 "gopkg.in/bblfsh/sdk.v1/protocol"
)

const (
// keepaliveMinTime is the minimum amount of time a client should wait before sending
// a keepalive ping.
keepaliveMinTime = 1 * time.Minute

// keepalivePingWithoutStream is a boolean flag.
// If true, server allows keepalive pings even when there are no active
// streams(RPCs). If false, and client sends ping when there are no active
// streams, server will send GOAWAY and close the connection.
keepalivePingWithoutStream = true
)

// Daemon is a Babelfish server.
type Daemon struct {
UserServer *grpc.Server
Expand All @@ -38,8 +52,16 @@ type Daemon struct {

// NewDaemon creates a new server based on the runtime with the given version.
func NewDaemon(version string, build time.Time, r *runtime.Runtime, opts ...grpc.ServerOption) *Daemon {
commonOpt := protocol2.ServerOptions()
opts = append(opts, commonOpt...)
commonOpt := append(protocol2.ServerOptions(),
// EnforcementPolicy is used to set keepalive enforcement policy on the
// server-side. Server will close connection with a client that violates this
// policy.
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: keepaliveMinTime,
PermitWithoutStream: keepalivePingWithoutStream,
}),
)
opts = append(commonOpt, opts...)

d := &Daemon{
version: version,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
github.com/prometheus/common v0.3.0 // indirect
github.com/prometheus/common v0.3.0
github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 // indirect
github.com/seccomp/libseccomp-golang v0.0.0-20170625204121-f6ec81daf48e // indirect
github.com/sirupsen/logrus v1.4.2
Expand Down