The current implementation of UniquePropertyMessageEvictionStrategy does not conform to the expected behaviour of a MessageEvictionStrategySupport implementation resulting in a memory leak.
All MessageEvictionStrategySupport implementations remove from the passed list of MessageReference objects the messages that should be evicted and then returns those items in an array. The calling code expects this to be the case and decrements message reference counters accordingly.
The current implementation of UniquePropertyMessageEvictionStrategy does one of two things depending on the state of the buffered messages:
- If the buffer already contains a single message per unique property then the oldest message is returned in the array for message removal but is not removed from the passed message list. This leaves a reference to the message intended for removal in the passed message reference list - not intended behaviour. (i.e. intended behaviour is identical to OldestMessageEvictionStrategy)
- If the buffer contains more than one instance of a message with the same unique property then only the latest messages (largest timestamp) for each of those sets are removed from the passed list of message references. At this point, the passed list of message references contains all the messages we expect to be removed so it is converted to an array and returned. But this list should contain all those messages that should be retained - not intended behaviour.
The patch contains the necessary changes to UniquePropertyMessageEvictionStrategy to prevent this memory leak and an assertion added to the UniquePropertyMessageEvictionStrategyTest.testEviction to demonstrate the memory is correctly freed after applying the fix.