-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from 6 commits
22a4bcd
591cdb0
bbe531c
1a34550
44a6d9d
33b9f9d
3ee692c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -49,8 +49,9 @@ const ( | |||||||
|
||||||||
type rpcHandler struct { | ||||||||
*Server | ||||||||
logger log.Logger | ||||||||
gologger *golog.Logger | ||||||||
logger log.Logger | ||||||||
gologger *golog.Logger | ||||||||
acceptLoopDelay time.Duration | ||||||||
} | ||||||||
|
||||||||
func newRpcHandler(s *Server) *rpcHandler { | ||||||||
|
@@ -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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||||
func (r *rpcHandler) handleAcceptErr(err error, ctx context.Context) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Go has an idiom of making |
||||||||
const baseAcceptLoopDelay = 5 * time.Millisecond | ||||||||
const maxAcceptLoopDelay = 5 * time.Second | ||||||||
const maxAcceptLoopDelayTemporaryError = 1 * time.Second | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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.