Page 1 of 1

Memory Leak - Activity objects not disposed in SmppSession.cs

Posted: Fri Nov 28, 2025 2:52 pm
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.