Skip to content

Commit b451379

Browse files
committed
Update eviction queue before size
See gh-25298
1 parent 44f1f94 commit b451379

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,9 @@ public LinkedMultiValueMap<String, String> getSubscriptions(String destination)
263263
if (sessionIdToSubscriptionIds == null) {
264264
sessionIdToSubscriptionIds = this.destinationCache.computeIfAbsent(destination, _destination -> {
265265
LinkedMultiValueMap<String, String> matches = computeMatchingSubscriptions(destination);
266-
this.cacheSize.incrementAndGet();
266+
// Update queue first, so that cacheSize <= queue.size(
267267
this.cacheEvictionPolicy.add(destination);
268+
this.cacheSize.incrementAndGet();
268269
return matches;
269270
});
270271
ensureCacheLimit();
@@ -309,7 +310,9 @@ private void ensureCacheLimit() {
309310
if (size > cacheLimit) {
310311
do {
311312
if (this.cacheSize.compareAndSet(size, size - 1)) {
312-
this.destinationCache.remove(this.cacheEvictionPolicy.poll());
313+
// Remove (vs poll): we expect an element
314+
String head = this.cacheEvictionPolicy.remove();
315+
this.destinationCache.remove(head);
313316
}
314317
} while ((size = this.cacheSize.get()) > cacheLimit);
315318
}

0 commit comments

Comments
 (0)