Memory Leak - Activity objects not disposed in SmppSession.cs

Post Reply
ggsa
Posts: 5
Joined: Mon Oct 13, 2025 7:12 am

Memory Leak - Activity objects not disposed in SmppSession.cs

Post by ggsa »

Hi alt,

We discovered a memory leak in our production environment. Memory grows from ~2GB to 3.6GB over one week and never releases.

Environment:
- Inetlab.SMPP version: 2.9.35
- .NET 8
- Linux

Memory profiler shows DiagNode<ActivityEvent> objects accumulating: see image1.jpeg

Memory growth over time: see image2.jpeg

Root Cause Analysis:

Found issue in SmppSession.cs - Activity objects not disposed for throttled requests.

Line 960 - throttled path:
_ = SendResponseAndDelayedRequests(resp, null, activity, _cancellationTokenSource.Token);

Activity is created at line 933 but SendResponseAndDelayedRequests never disposes it. Only HandleReceivedRequest disposes activity at line 718, but throttled requests bypass this method.

Suggested Fix:

Add activity?.Dispose() in SendResponseAndDelayedRequests or wrap throttled call:

// Option 1: Dispose after fire-and-forget completes
_ = SendResponseAndDelayedRequests(resp, null, activity, _cancellationTokenSource.Token)
.ContinueWith(_ => activity?.Dispose());

// Option 2: Add try-finally in SendResponseAndDelayedRequests

Can you please review and confirm?

Thank you.
Attachments
image2.jpg
image2.jpg (219.09 KiB) Viewed 27 times
image1.jpeg
image1.jpeg (234.2 KiB) Viewed 27 times
Post Reply