fix: address memory leaks in channels, transports, and listeners; update Newtonsoft.Json to 13.0.1#102
fix: address memory leaks in channels, transports, and listeners; update Newtonsoft.Json to 13.0.1#102Copilot wants to merge 4 commits into
Conversation
- ChannelBase: unsubscribe Transport.Closing event handler in Dispose to prevent the channel being kept alive through the transport's event list - RemotePingChannelModule: wait up to 5 s for the background ping task to complete in Dispose so the task never outlives the module - EnvelopePipe: dispose the internal SemaphoreSlim in Dispose - CloseWithTimeoutAsync (TcpTransport, PipeTcpTransport, WebSocketTransport, PipeWebSocketTransport): make async/await so the CancellationTokenSource is not disposed while the close task is still running - TransportBase: implement IDisposable and dispose the _openCloseSemaphore; add base.Dispose(disposing) calls in all concrete subclasses (TcpTransport, PipeTcpTransport, WebSocketTransport, PipeWebSocketTransport, RedisTransport) - SynchronizedTransportDecorator: implement IDisposable to dispose the two SemaphoreSlim instances it owns - TcpTransportListener / PipeTcpTransportListener: implement IDisposable to dispose the SemaphoreSlim - RedisTransportListener: also dispose the SemaphoreSlim in Dispose - HttpContextChannel: implement IDisposable to dispose the SemaphoreSlim - BufferedChannelListener: dispose the previous (cancelled) CTS at the top of Start() before replacing it with a new one Agent-Logs-Url: https://github.com/takenet/lime-csharp/sessions/478e457f-8cd4-404f-9d9e-aab34cb9c31a Co-authored-by: leonardo-avila <29763488+leonardo-avila@users.noreply.github.com>
…nsports and channels Agent-Logs-Url: https://github.com/takenet/lime-csharp/sessions/478e457f-8cd4-404f-9d9e-aab34cb9c31a Co-authored-by: leonardo-avila <29763488+leonardo-avila@users.noreply.github.com>
|
Policy Management Violations (2)Policy Name: Politica Geral - Exploitable Path
Policy Name: CVE-2024-21907The following violations of your team's AppSec policy rules were identified in this project. Since 'Break Build' is enabled for these rules, you must resolve these issues before the Pull Request can be merged.
Communicate with Checkmarx by submitting a PR comment with @Checkmarx followed by one of the supported commands. Learn about the supported commands here. |
… for memory leak fix The synchronous Wait() could block the calling thread for up to 5 s during disposal. The original CancelAndDispose() already signals the background task to stop; the task itself holds no resources that need explicit cleanup. Agent-Logs-Url: https://github.com/takenet/lime-csharp/sessions/815e9599-1f2d-468d-a33e-a311cdcb2e78 Co-authored-by: leonardo-avila <29763488+leonardo-avila@users.noreply.github.com>
|
@copilot Update Newtonsoft.Json package to version 13.0.1 to fix some vulnerability issues. |
…ulnerability Agent-Logs-Url: https://github.com/takenet/lime-csharp/sessions/8ef89f91-6fcc-4076-bf43-9cc9a8dff9e3 Co-authored-by: leonardo-avila <29763488+leonardo-avila@users.noreply.github.com>
Done in commit |

Fixes ten memory-leak categories identified by static analysis and updates Newtonsoft.Json to address a known vulnerability. No new public APIs are added; the changes only add proper disposal of existing resources and correct one async-return bug.
Changes
Memory Leak Fixes
ChannelBase: unsubscribeTransport.Closingevent inDisposeto prevent channels from being kept alive through event delegates when transports outlive channels.CloseWithTimeoutAsync(TcpTransport,PipeTcpTransport,WebSocketTransport,PipeWebSocketTransport): madeasync/awaitso theCancellationTokenSourceusingscope spans the full operation and is not disposed while the task is still running.EnvelopePipe.Dispose(): added missing_semaphore.Dispose().SynchronizedTransportDecorator: implementIDisposableto dispose twoSemaphoreSliminstances that were never disposed.TransportBase: implementIDisposable(protected virtualDispose(bool)/ publicDispose()) to dispose_openCloseSemaphore; all concrete subclasses (TcpTransport,PipeTcpTransport,WebSocketTransport,PipeWebSocketTransport,RedisTransport) callbase.Dispose(disposing).TcpTransportListener/PipeTcpTransportListener: implementIDisposableto dispose theSemaphoreSlim.RedisTransportListener.Dispose(): also dispose theSemaphoreSlim(previously only the connection multiplexer was disposed).HttpContextChannel: implementIDisposableto dispose_sendSemaphore.BufferedChannelListener.Start(): dispose the previous cancelledCancellationTokenSourcebefore replacing it with a new one.Security Fix
Lime.Client.Windows(packages.configandLime.Client.Windows.csproj) to address the improper handling of exceptional conditions vulnerability (patched in 13.0.1). All other projects were already on 13.0.1.Testing
Lime.Protocol.UnitTests: 527 passed / 1 pre-existing failure (a timing-sensitiveResendMessagestest that also fails onmainwithout these changes).