Copilot commented on code in PR #5908:
URL: https://github.com/apache/ignite-3/pull/5908#discussion_r2109114544


##########
modules/core/src/main/java/org/apache/ignite/internal/streamer/StreamerSubscriber.java:
##########
@@ -356,24 +356,36 @@ private void completeWithError(Throwable throwable) {
         }
     }
 
-    private synchronized void requestMore() {
-        if (closed || subscription == null) {
-            return;
-        }
+    private void requestMore() {
+        int toRequest;
+        Subscription sub;
 
-        // This method controls backpressure. We won't get more items than we 
requested.
-        // The idea is to have perPartitionParallelOperations batches in 
flight for every connection.
-        var pending = pendingItemCount.get();
-        var desiredInFlight = Math.max(1, buffers.size()) * options.pageSize() 
* options.perPartitionParallelOperations();
-        var inFlight = inFlightItemCount.get();
-        var count = desiredInFlight - inFlight - pending;
+        synchronized (this) {
+            if (closed || subscription == null) {
+                return;
+            }
 
-        if (count <= 0) {
-            return;
+            // This method controls backpressure. We won't get more items than 
we requested.
+            // The idea is to have perPartitionParallelOperations batches in 
flight for every connection.
+            var pending = pendingItemCount.get();
+            var desiredInFlight = Math.max(1, buffers.size()) * 
options.pageSize() * options.perPartitionParallelOperations();
+            var inFlight = inFlightItemCount.get();
+            toRequest = desiredInFlight - inFlight - pending;
+
+            if (toRequest <= 0) {
+                return;
+            }
+
+            pendingItemCount.addAndGet(toRequest);
+            sub = subscription;
         }
 
-        subscription.request(count);
-        pendingItemCount.addAndGet(count);
+        try {
+            sub.request(toRequest);

Review Comment:
   Consider adding a comment here to clarify that invoking sub.request() 
outside the synchronized block is intentional to avoid potential deadlocks by 
not holding locks during user code execution.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to