From 3a32180cf809de4ff2ea2ddba9e1a146d536ab5c Mon Sep 17 00:00:00 2001
From: Nikita Koksharov <nkoksharov@redisson.pro>
Date: Thu, 31 Oct 2024 09:06:28 +0300
Subject: [PATCH] Fixed - pollAsync() and removeAsync() methods of
 RPriorityQueue and RPriorityDeque objects aren't guarded properly with lock.

---
 .../src/main/java/org/redisson/RedissonPriorityQueue.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java b/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java
index ed64c50f3..a3992c877 100644
--- a/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java
+++ b/redisson/src/main/java/org/redisson/RedissonPriorityQueue.java
@@ -273,19 +273,19 @@ public class RedissonPriorityQueue<V> extends BaseRedissonList<V> implements RPr
         return wrapLockedAsync(RedisCommands.LPOP, getRawName());
     }
 
-    protected <T> RFuture<V> wrapLockedAsync(RedisCommand<T> command, Object... params) {
+    protected final <T> RFuture<V> wrapLockedAsync(RedisCommand<T> command, Object... params) {
         return wrapLockedAsync(() -> {
             return commandExecutor.writeAsync(getRawName(), codec, command, params);
         });
     }
 
     protected final <T, R> RFuture<R> wrapLockedAsync(Supplier<RFuture<R>> callable) {
-        long threadId = Thread.currentThread().getId();
-        CompletionStage<R> f = lock.lockAsync(threadId).thenCompose(r -> {
+        long randomId = getServiceManager().generateValue();
+        CompletionStage<R> f = lock.lockAsync(randomId).thenCompose(r -> {
             RFuture<R> callback = callable.get();
             return callback.handle((value, ex) -> {
                 CompletableFuture<R> result = new CompletableFuture<>();
-                lock.unlockAsync(threadId)
+                lock.unlockAsync(randomId)
                         .whenComplete((r2, ex2) -> {
                             if (ex2 != null) {
                                 if (ex != null) {