asynkron/protoactor-dotnet

Memory leak in ServerEndpoint channels

AqlaSolutions opened this issue ยท 2 comments

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?

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.

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