Skip to content

Commit 0a78c99

Browse files
committed
avoid infinite loop by passing nextToken to DescribeInstance
1 parent c0db492 commit 0a78c99

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/cloudproviders/aws/aws.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ func (p *Provider) Instance(ctx context.Context, IP ...gostatsd.Source) (map[gos
8282
values[i] = string(ip)
8383
}
8484
privateIPFilter := "private-ip-address"
85-
input := &ec2.DescribeInstancesInput{
86-
Filters: []ec2Types.Filter{
87-
{
88-
Name: &privateIPFilter,
89-
Values: values,
90-
},
85+
inputFilters := []ec2Types.Filter{
86+
{
87+
Name: &privateIPFilter,
88+
Values: values,
9189
},
9290
}
9391

@@ -96,12 +94,19 @@ func (p *Provider) Instance(ctx context.Context, IP ...gostatsd.Source) (map[gos
9694
instancesFound := uint64(0)
9795
pages := uint64(0)
9896
var err error
97+
var nextToken string
9998

10099
p.logger.WithField("ips", IP).Debug("Looking up instances")
101100
hasPagesRemaining := true
102101
for hasPagesRemaining {
103102
pages++
103+
input := &ec2.DescribeInstancesInput{
104+
Filters: inputFilters,
105+
NextToken: &nextToken,
106+
}
107+
104108
page, rawErr := p.Ec2.DescribeInstances(ctx, input)
109+
nextToken = *page.NextToken
105110
if rawErr != nil {
106111
atomic.AddUint64(&p.describeInstanceErrors, 1)
107112
hasPagesRemaining = false

0 commit comments

Comments
 (0)