Refinitiv / Real-Time-SDK

Other
186 stars 129 forks source link

Memory leak in Java\WlDirectoryHandler\_directoryRefreshPool #279

Closed lukeabsent closed 4 days ago

lukeabsent commented 4 months ago

Hi,

_directoryRefreshPool is growing over time, and keeps adding the same object over and over, through this there is a memory leak plus some possible functional bug, cause in case of concurrent usage, the same object may be fetched from this pool _directoryRefreshPool multiple times. The issue seems to be present in every method that makes use of this list. Please have a look at one function as example: int dispatch(ReactorErrorInfo errorInfo) there is this piece

if (!_directoryRefreshPool.isEmpty())
            {
                newDirectoryRefresh = _directoryRefreshPool.poll();

however it can be returned multiple times

for (int i = 0; i < _stream.userRequestList().size(); i++)
            {

... and within that loop is this _directoryRefreshPool.add(newDirectoryRefresh);

I believe it should be assured object is returned just single time to the pool plus perhaps adding some synchronization to it. I've seen this list growing to big number and containing the same object (I didnt check every position of list though)

vlevendel commented 4 months ago

@lukeabsent Thank you for creating this issue. Which version of API are you using? Would you please share an application code snippet that results in memory growth over time? What is the server side your are connecting to?

lukeabsent commented 4 months ago

I think it was eta/ema 3.6.8.0 (maven version). I dont have any snippet I could share, but hopefully it should be quite obvious that there is an issue for someone analyzing these methods (methods from WlDirectoryHandler class that make use of _directoryRefreshPool field).

soranat commented 4 months ago

@lukeabsent

The dispatch(ReactorErrorInfo errorInfo) function will be fixed to return the DirectoryRefresh object only once to the _directoryRefreshPool as same as the other methods which uses the _directoryRefreshPool to reuse the DirectoryRefresh object.

vlevendel commented 4 months ago

@lukeabsent A fix will be provided in a future release.

lukeabsent commented 4 months ago

@vlevendel @soranat Thank you