Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix memory leak in GelfChunkAggregator #1488
The memory leak showed up because of a problem in the ChunkEntry#compareTo() method.
If two ChunkEntry objects had the same firstTimestamp value, the compareTo() method returned a wrong result because only the timestamp has been taken into account. This made sortedEvictionSet.remove(entry) not remove the entry from the set in some cases.
The GelfChunkAggregator class maintains a chunks ConcurrentMap and a sortedEvictionSet ConcurrentSkipListSet with ChunkEntry objects. The ChunkEvictionTask gets the first entry from the sortedEvictionSet and basically removes it from the chunks map and then tries to remove it from the sortedEvictionSet as well.
The removal from the chunks map works, the removal from the sortedEvictionSet does not work. (due to the compareTo() bug)
During the next scheduled execution of ChunkEvictionTask#run(), the same entry is returned from the sortedEvictionSet. This entry is not in the chunks map anymore so chunks.remove(entry) returns null. The return value is used to remove the entry from the sortedEvictionSet. This throws a NullPointerException because the return value was null. This NPE was ignored and not logged.
This change fixes the ChunkEntry#compareTo() method to compare the ID if both timestamps are equal. We also now log any error that happens during a ChunkEvictionTask#run() execution.
See #1462 for details.