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

Fix qproxy error #11

Merged
merged 2 commits into from
Jul 9, 2020
Merged
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
44 changes: 23 additions & 21 deletions backends/sqs/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,33 +165,32 @@ func (s *Backend) ListQueues(in *rpc.ListQueuesRequest, stream rpc.QProxy_ListQu
QueueNamePrefix: &in.Namespace,
}
ctx := stream.Context()
count := 0
var queues []*string
err = s.sqs.ListQueuesPagesWithContext(ctx, input,
func(page *sqs.ListQueuesOutput, lastPage bool) bool {
count += len(page.QueueUrls)
for idx, url := range page.QueueUrls {
if idx != 0 && idx%100 == 0 {
stream.Send(&rpc.ListQueuesResponse{
Queues: buf,
})
buf = make([]*rpc.QueueId, 0, 100)
}

if queueId, err := QueueUrlToQueueId(*url); err != nil {
log.Printf("Got error while converting queue url: %v", err)
return false
} else if strings.Contains(queueId.Name, in.Filter) {
buf = append(buf, queueId)
}
}
queues = append(queues, page.QueueUrls...)
return true
})
if err != nil {
log.Printf("Got error while querying sqs: %v", err)
return err
}
log.Printf("ListQueue results: Got total %v queues", count)

for idx, url := range queues {
if idx != 0 && idx%100 == 0 {
stream.Send(&rpc.ListQueuesResponse{
Queues: buf,
})
buf = make([]*rpc.QueueId, 0, 100)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do buf = buf[:0] it'll reuse the memory and not re-allocate

}

if queueId, err := QueueUrlToQueueId(*url); err != nil {
log.Printf("Got error while converting queue url: %v", err)
return err
} else if strings.Contains(queueId.Name, in.Filter) {
buf = append(buf, queueId)
}
}
// Send any remaining queues not flushed
stream.Send(&rpc.ListQueuesResponse{
Queues: buf,
Expand Down Expand Up @@ -231,7 +230,8 @@ func (s *Backend) CreateQueue(ctx context.Context, in *rpc.CreateQueueRequest) (
queueName := QueueIdToName(in.Id)
attributes := make(map[string]*string)
for k, v := range in.Attributes {
attributes[k] = &v
value := v
attributes[k] = &value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could also be &in.Attributes[k]. The issue here is that the for loop variables are shallow copies, so they can't be referenced across the loop.

}
output, err := s.sqs.CreateQueueWithContext(ctx, &sqs.CreateQueueInput{
QueueName: queueName,
Expand Down Expand Up @@ -271,7 +271,8 @@ func (s *Backend) ModifyQueue(ctx context.Context, in *rpc.ModifyQueueRequest) (

attributes := make(map[string]*string)
for k, v := range in.Attributes {
attributes[k] = &v
value := v
attributes[k] = &value
}
_, err = s.sqs.SetQueueAttributesWithContext(ctx, &sqs.SetQueueAttributesInput{
QueueUrl: &url,
Expand Down Expand Up @@ -311,9 +312,10 @@ func (s *Backend) AckMessages(ctx context.Context, in *rpc.AckMessagesRequest) (
entries := make([]*sqs.DeleteMessageBatchRequestEntry, 0, len(in.Receipts))
for idx, receipt := range in.Receipts {
strIdx := strconv.Itoa(idx)
handle := receipt.Id
entries = append(entries, &sqs.DeleteMessageBatchRequestEntry{
Id: &strIdx,
ReceiptHandle: &receipt.Id,
ReceiptHandle: &handle,
})
}

Expand Down