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

core: add 50 hop limit to rpc forwarding #16577

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
core: add 50 hop limit to rpc forwarding
schmichael committed Mar 20, 2023
commit f19c3430bbb4e9122b02b2ecbfff9dbb7af3d88e
4 changes: 4 additions & 0 deletions nomad/rpc.go
Original file line number Diff line number Diff line change
@@ -535,6 +535,10 @@ func (r *rpcHandler) handleMultiplexV2(ctx context.Context, conn net.Conn, rpcCt
// forward is used to forward to a remote region or to forward to the local leader
// Returns a bool of if forwarding was performed, as well as any error
func (r *rpcHandler) forward(method string, info structs.RPCInfo, args interface{}, reply interface{}) (bool, error) {
if info.NumHops() > 50 {
return true, fmt.Errorf("exceeded hop limit")
}

region := info.RequestRegion()
if region == "" {
return true, fmt.Errorf("missing region for target RPC")
7 changes: 7 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
@@ -228,6 +228,7 @@ type RPCInfo interface {
AllowStaleRead() bool
IsForwarded() bool
SetForwarded()
NumHops() int16
TimeToBlock() time.Duration
// SetTimeToBlock sets how long this request can block. The requested time may not be possible,
// so Callers should readback TimeToBlock. E.g. you cannot set time to block at all on WriteRequests
@@ -240,6 +241,11 @@ type RPCInfo interface {
type InternalRpcInfo struct {
// Forwarded marks whether the RPC has been forwarded.
Forwarded bool
Hops int16
}

func (i *InternalRpcInfo) NumHops() int16 {
return i.Hops
}

// IsForwarded returns whether the RPC is forwarded from another server.
@@ -250,6 +256,7 @@ func (i *InternalRpcInfo) IsForwarded() bool {
// SetForwarded marks that the RPC is being forwarded from another server.
func (i *InternalRpcInfo) SetForwarded() {
i.Forwarded = true
i.Hops++
}

// QueryOptions is used to specify various flags for read queries