Skip to content

Commit

Permalink
[azservicebus] Fixing memory leak with go-amqp update. (#22253)
Browse files Browse the repository at this point in the history
go-amqp got a fix recently that replaces its internal tracking map with a counter, which eliminates a rare memory leak we'd see if you were settling a message on a separate receiver _while_ the other receiver was still alive.

In recovery scenarios, we discard the old Receiver instance, making this a non-issue for our typical use case.

Fixes #22157
  • Loading branch information
richardpark-msft authored Jan 17, 2024
1 parent ca1debf commit 6d37f43
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions sdk/messaging/azservicebus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

- ReceiverOptions.TimeAfterFirstMessage lets you configure the amount of time, after the first message in a batch is received, before we return messages. (PR#22154)

### Bugs Fixed

- Settling a message (using CompleteMessage, AbandonMessage, etc..) on a different Receiver instance than you received on no
longer leaks memory. (PR#22253)

## 1.5.0 (2023-10-10)

### Features Added
Expand Down
2 changes: 1 addition & 1 deletion sdk/messaging/azservicebus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0
github.com/Azure/go-amqp v1.0.2
github.com/Azure/go-amqp v1.0.4
)

require (
Expand Down
4 changes: 2 additions & 2 deletions sdk/messaging/azservicebus/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0 h1:Yoicul8bnVdQrhDMTHxdE
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0/go.mod h1:+6sju8gk8FRmSajX3Oz4G5Gm7P+mbqE9FVaXXFYTkCM=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0 h1:TuEMD+E+1aTjjLICGQOW6vLe8UWES7kopac9mUXL56Y=
github.com/Azure/azure-sdk-for-go/sdk/internal v1.4.0/go.mod h1:s4kgfzA0covAXNicZHDMN58jExvcng2mC/DepXiF1EI=
github.com/Azure/go-amqp v1.0.2 h1:zHCHId+kKC7fO8IkwyZJnWMvtRXhYC0VJtD0GYkHc6M=
github.com/Azure/go-amqp v1.0.2/go.mod h1:vZAogwdrkbyK3Mla8m/CxSc/aKdnTZ4IbPxl51Y5WZE=
github.com/Azure/go-amqp v1.0.4 h1:GX5OFOs706UjuFRD5PDKm3aOuLQ92F7DMbua+DKAYCc=
github.com/Azure/go-amqp v1.0.4/go.mod h1:vZAogwdrkbyK3Mla8m/CxSc/aKdnTZ4IbPxl51Y5WZE=
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c=
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
32 changes: 32 additions & 0 deletions sdk/messaging/azservicebus/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,38 @@ import (
"github.com/stretchr/testify/require"
)

func TestReceiverBackupSettlement(t *testing.T) {
serviceBusClient, cleanup, queueName := setupLiveTest(t, &liveTestOptions{
QueueProperties: &admin.QueueProperties{
LockDuration: to.Ptr("PT5M"),
},
})
defer cleanup()

sender, err := serviceBusClient.NewSender(queueName, nil)
require.NoError(t, err)

err = sender.SendMessage(context.Background(), &Message{
Body: []byte("hello world"),
}, nil)
require.NoError(t, err)

origReceiver, err := serviceBusClient.NewReceiverForQueue(queueName, nil)
require.NoError(t, err)
defer test.RequireClose(t, origReceiver)

otherReceiver, err := serviceBusClient.NewReceiverForQueue(queueName, nil)
require.NoError(t, err)
defer test.RequireClose(t, otherReceiver)

messages, err := origReceiver.ReceiveMessages(context.TODO(), 1, nil)
require.NoError(t, err)
require.NotEmpty(t, messages)

err = otherReceiver.CompleteMessage(context.Background(), messages[0], nil)
require.NoError(t, err)
}

func TestReceiverCancel(t *testing.T) {
serviceBusClient, cleanup, queueName := setupLiveTest(t, nil)
defer cleanup()
Expand Down

0 comments on commit 6d37f43

Please sign in to comment.