asynkron / protoactor-dotnet

Proto Actor - Ultra fast distributed actors for Go, C# and Java/Kotlin
http://proto.actor
Apache License 2.0
1.74k stars 288 forks source link

Memory leak in ServerEndpoint channels #2110

Closed AqlaSolutions closed 7 months ago

AqlaSolutions commented 8 months ago

Hi, we've encountered an issue that after some time of load testing the memory usage increases and never goes down even after stopping sending new requests. From dotMemory snapshot: image

What can cause this?

AqlaSolutions commented 8 months ago

It looks like the issue might be related to this part of Endpoint class image

With each loop iteration you perform a new call to WaitToReadAsync and create 2 new tasks for both readers even when only one of the previous two task was completed. This enqueues a new AsyncOperation instance each time which is not removed until anything is written to the channel. So, to avoid this issue, re-use the existing reader task when it's not completed.

Also, as an optimization, consider checking the IsCompleted property of these ValueTasks before calling AsTask and waiting.

AqlaSolutions commented 7 months ago

No memory leak after 4 days of testing the merged fix, closing this.