azure-sdk-for-go: [azservicebus] Memory leak when receiving messages

Bug Report

  • Package in question azure-sdk-for-go/sdk/messaging/azservicebus
  • SDK version v1.5.0
  • go version 1.21
  • What happened?

We are trying to move away from the deprecated azure sdk for service bus https://github.com/Azure/azure-service-bus-go and use e the new in one of our services. This service is heavily reading on messages from a Service Bus Queue. We are noticing an increasing usage of memory.

Screenshot 2023-12-18 at 12 38 00

Also from profiling data we can see that the Heap size increase is happening at go-ampq code

Screenshot 2023-12-18 at 12 41 48

  • What did you expect or want to happen?

I would expect the new SDK to have a different memory footprint (either higher or lower memory consumption) but after some time i was expecting the memory usage of the service to be stable as before and not increasing time over time.

  • How can we reproduce it?

Not sure how easy it is, as we need to leave the service running for a couple of days to start seeing the increase in memory usage.

  • Anything we should know about your environment.

Data shared above are from staging environment. I am expecting bigger usage on a prod environment with much higher traffic.

Our setup is we are using a number of worker goroutines each one receiving messages from a client.Receiver in parallel.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 28 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Richard and I spoke about this offline. The reason the go-amqp@v1.0.3 change didn’t fix this is because cross-receiver settlement at the azservicebus level bypasses the go-amqp layer.

I’ve released go-amqp@v1.0.4 which replaces the unsettled messages map with a count which should fix this.

@gkampitakis FYI we’ll be releasing an updated go-amqp (should be today) that fixes the cross-receiver message settlement memory leak.

@richardpark-msft

We are using a pool of receivers to ReceiveMessages concurrently from multiple goroutines, process them and then complete them. So from the pool you pick a random (available) receiver to ReceiveMessages and then have a single receiver that settles the messages.

Thanks both for your time spent on this 🙇. I couldn’t have figure it out. Will try to work around this and use the same receiver for both operations.