Skip to content

Commit

Permalink
Avoid 'transport closing' errors on client side
Browse files Browse the repository at this point in the history
Signed-off-by: kuba-- <kuba@sourced.tech>
  • Loading branch information
kuba-- authored and dennwc committed Jul 11, 2019
1 parent e07d4fd commit 0a15852
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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

0 comments on commit 0a15852

Please sign in to comment.