From f0b434d518cc9246711fbc21c7b4d72f69a654e7 Mon Sep 17 00:00:00 2001 From: Paul Lorenz Date: Wed, 22 Mar 2023 16:22:17 -0400 Subject: [PATCH] Rate limit terminator creation for router/tunneler. Fixes #1362 --- go.mod | 2 +- go.sum | 4 ++-- router/xgress_edge_tunnel/fabric.go | 10 +++++++++- router/xgress_edge_tunnel/factory.go | 8 +++++--- tests/context.go | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 1b87687ed..94732cda1 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/netfoundry/secretstream v0.1.5 github.com/openziti/channel/v2 v2.0.53 github.com/openziti/edge-api v0.25.8 - github.com/openziti/fabric v0.22.72 + github.com/openziti/fabric v0.22.73 github.com/openziti/foundation/v2 v2.0.18 github.com/openziti/identity v1.0.42 github.com/openziti/jwks v1.0.3 diff --git a/go.sum b/go.sum index 886a1ca1f..1ccb9178c 100644 --- a/go.sum +++ b/go.sum @@ -457,8 +457,8 @@ github.com/openziti/channel/v2 v2.0.53 h1:qHcGpbHCg6GqpHxFs4qfk4X2DJIv3YEx7ePX6L github.com/openziti/channel/v2 v2.0.53/go.mod h1:/AA0mtP4z+N59+vB8SJD72PfSQWSwrVqWZgR7YTXlEo= github.com/openziti/edge-api v0.25.8 h1:7JXRq6KagTBH9Pb8cgpNTXqpHfQal1wXpgIOUjFMoUM= github.com/openziti/edge-api v0.25.8/go.mod h1:vroL28d1rJzosnSXMfQrKc7Cbil7sGhH/BqLw+RwNKc= -github.com/openziti/fabric v0.22.72 h1:Jg8fR7gLOVm/crZYssfvcbA+3oYI/Pr2GVk6NOq380g= -github.com/openziti/fabric v0.22.72/go.mod h1:u3FBErE9yUpE46M+tjitbBAQKQ6318PnRhe3wFvL9oM= +github.com/openziti/fabric v0.22.73 h1:mOvgLKBWW4X91pzIuZBtN6cZdxXWmtgpPLVnRbkU4MQ= +github.com/openziti/fabric v0.22.73/go.mod h1:u3FBErE9yUpE46M+tjitbBAQKQ6318PnRhe3wFvL9oM= github.com/openziti/foundation/v2 v2.0.18 h1:ehXqKT7aEGLpjaAn5T+CnvCqz1DQIFa0Z2f+DzyGvzw= github.com/openziti/foundation/v2 v2.0.18/go.mod h1:lLIVb/foLtVQ1Gv0VnfVmnSg/vMKU1HslYMc6rEymf4= github.com/openziti/identity v1.0.42 h1:FcaPDNzpQ0+JSgaaiykEkjhd9XcyVpi3rzLhVQI3qKc= diff --git a/router/xgress_edge_tunnel/fabric.go b/router/xgress_edge_tunnel/fabric.go index 1dd12bc73..730cd8ad2 100644 --- a/router/xgress_edge_tunnel/fabric.go +++ b/router/xgress_edge_tunnel/fabric.go @@ -39,6 +39,7 @@ import ( "github.com/pkg/errors" "github.com/sirupsen/logrus" "google.golang.org/protobuf/proto" + "math" "net" "runtime" "strings" @@ -283,7 +284,14 @@ func (self *fabricProvider) HostService(hostCtx tunnel.HostingContext) (tunnel.H self.tunneler.terminators.Set(terminator.id, terminator) - go self.establishTerminatorWithRetry(terminator) + err = self.factory.env.GetRateLimiterPool().QueueWithTimeout(func() { + self.establishTerminatorWithRetry(terminator) + }, math.MaxInt64) + + if err != nil { + self.tunneler.terminators.Set(terminator.id, terminator) + return nil, err + } return terminator, nil } diff --git a/router/xgress_edge_tunnel/factory.go b/router/xgress_edge_tunnel/factory.go index 987d2c293..e5e85e1a4 100644 --- a/router/xgress_edge_tunnel/factory.go +++ b/router/xgress_edge_tunnel/factory.go @@ -48,6 +48,7 @@ type Factory struct { serviceListHandler *handler_edge_ctrl.ServiceListHandler tunneler *tunneler metricsRegistry metrics.UsageRegistry + env env.RouterEnv } func (self *Factory) NotifyOfReconnect(channel.Channel) { @@ -87,12 +88,13 @@ func (self *Factory) DefaultRequestTimeout() time.Duration { } // NewFactory constructs a new Edge Xgress Tunnel Factory instance -func NewFactory(routerConfig *router.Config, stateManager fabric.StateManager, metricsRegistry metrics.UsageRegistry) *Factory { +func NewFactory(env env.RouterEnv, routerConfig *router.Config, stateManager fabric.StateManager) *Factory { factory := &Factory{ - id: routerConfig.Id, + id: env.GetRouterId(), routerConfig: routerConfig, stateManager: stateManager, - metricsRegistry: metricsRegistry, + metricsRegistry: env.GetMetricsRegistry(), + env: env, } factory.tunneler = newTunneler(factory, stateManager) return factory diff --git a/tests/context.go b/tests/context.go index 70d339651..592f4ddfe 100644 --- a/tests/context.go +++ b/tests/context.go @@ -463,7 +463,7 @@ func (ctx *TestContext) startEdgeRouter() { xgressEdgeFactory := xgress_edge.NewFactory(config, NewVersionProviderTest(), stateManager, ctx.router.GetMetricsRegistry()) xgress.GlobalRegistry().Register(edge_common.EdgeBinding, xgressEdgeFactory) - xgressEdgeTunnelFactory := xgress_edge_tunnel.NewFactory(config, stateManager, ctx.router.GetMetricsRegistry()) + xgressEdgeTunnelFactory := xgress_edge_tunnel.NewFactory(ctx.router, config, stateManager) xgress.GlobalRegistry().Register(edge_common.TunnelBinding, xgressEdgeTunnelFactory) ctx.Req.NoError(ctx.router.RegisterXrctrl(xgressEdgeFactory))