From 557d39be2a575c8a340ead48af2fc6e709d52a00 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 9 Nov 2024 09:26:49 +0100 Subject: Merging upstream version 1.47.5. Signed-off-by: Daniel Baumann --- .../discovery/sd/discoverer/netlisteners/netlisteners.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/go/plugin/go.d/agent') diff --git a/src/go/plugin/go.d/agent/discovery/sd/discoverer/netlisteners/netlisteners.go b/src/go/plugin/go.d/agent/discovery/sd/discoverer/netlisteners/netlisteners.go index 6f536c49e..60dd92cb4 100644 --- a/src/go/plugin/go.d/agent/discovery/sd/discoverer/netlisteners/netlisteners.go +++ b/src/go/plugin/go.d/agent/discovery/sd/discoverer/netlisteners/netlisteners.go @@ -84,6 +84,9 @@ type ( cache map[uint64]*cacheItem // [target.Hash] started chan struct{} + + successRuns int64 + timeoutRuns int64 } cacheItem struct { lastSeenTime time.Time @@ -118,7 +121,7 @@ func (d *Discoverer) Discover(ctx context.Context, in chan<- []model.TargetGroup return case <-tk.C: if err := d.discoverLocalListeners(ctx, in); err != nil { - d.Warning(err) + d.Error(err) return } } @@ -128,12 +131,20 @@ func (d *Discoverer) Discover(ctx context.Context, in chan<- []model.TargetGroup func (d *Discoverer) discoverLocalListeners(ctx context.Context, in chan<- []model.TargetGroup) error { bs, err := d.ll.discover(ctx) if err != nil { - if errors.Is(err, context.Canceled) { + if errors.Is(err, context.DeadlineExceeded) { + // there is no point in continuing pointless attempts/use cpu + // https://github.com/netdata/netdata/discussions/18751#discussioncomment-10908472 + if d.timeoutRuns++; d.timeoutRuns > 5 && d.successRuns == 0 { + return err + } + d.Warning(err) return nil } return err } + d.successRuns++ + tgts, err := d.parseLocalListeners(bs) if err != nil { return err -- cgit v1.2.3