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

rpc accept loop: added backoff on logging #4974

Merged
merged 7 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
43 changes: 33 additions & 10 deletions nomad/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ const (

type rpcHandler struct {
*Server
logger log.Logger
gologger *golog.Logger
logger log.Logger
gologger *golog.Logger
acceptLoopDelay time.Duration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define this within listen() and pass it to the error handler method unless you put it here for testing.

}

func newRpcHandler(s *Server) *rpcHandler {
Expand Down Expand Up @@ -98,22 +99,44 @@ func (r *rpcHandler) listen(ctx context.Context) {
if r.shutdown {
return
}

select {
case <-ctx.Done():
return
default:
}

r.logger.Error("failed to accept RPC conn", "error", err)
r.handleAcceptErr(err, ctx)
continue
}
// No error, reset loop delay
r.acceptLoopDelay = 0

go r.handleConn(ctx, conn, &RPCContext{Conn: conn})
metrics.IncrCounter([]string{"nomad", "rpc", "accept_conn"}, 1)
}
}

// Sleep to avoid spamming the log, with a maximum delay according to whether or not the error is temporary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go has an idiom of starting method comments with the name of the method. No big deal.

Suggested change
// Sleep to avoid spamming the log, with a maximum delay according to whether or not the error is temporary
// handleAcceptErr sleeps to avoid spamming the log, with a maximum delay
// according to whether or not the error is temporary.

func (r *rpcHandler) handleAcceptErr(err error, ctx context.Context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go has an idiom of making ctx the first argument in method calls.

const baseAcceptLoopDelay = 5 * time.Millisecond
const maxAcceptLoopDelay = 5 * time.Second
const maxAcceptLoopDelayTemporaryError = 1 * time.Second
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can shorten the names since they're locals: baseDelay, maxDelay, maxDelayTempError

No need to change.


if r.acceptLoopDelay == 0 {
r.acceptLoopDelay = baseAcceptLoopDelay
} else {
r.acceptLoopDelay *= 2
}
temporaryError := false
if ne, ok := err.(net.Error); ok && ne.Temporary() {
temporaryError = true
}
if temporaryError && r.acceptLoopDelay > maxAcceptLoopDelayTemporaryError {
r.acceptLoopDelay = maxAcceptLoopDelayTemporaryError
} else if r.acceptLoopDelay > maxAcceptLoopDelay {
r.acceptLoopDelay = maxAcceptLoopDelay
}
r.logger.Error("failed to accept RPC conn", "error", err, "delay", r.acceptLoopDelay)
select {
case <-ctx.Done():
case <-time.After(r.acceptLoopDelay):
}
}

// handleConn is used to determine if this is a Raft or
// Nomad type RPC connection and invoke the correct handler
func (r *rpcHandler) handleConn(ctx context.Context, conn net.Conn, rpcCtx *RPCContext) {
Expand Down
8 changes: 7 additions & 1 deletion vendor/github.com/hashicorp/memberlist/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 8 additions & 77 deletions vendor/github.com/hashicorp/memberlist/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 36 additions & 13 deletions vendor/github.com/hashicorp/memberlist/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/hashicorp/memberlist/delegate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading