adityamukho commented on code in PR #7488:
URL: https://github.com/apache/ignite-3/pull/7488#discussion_r2803254087


##########
modules/network/src/main/java/org/apache/ignite/internal/network/DefaultMessagingService.java:
##########
@@ -651,7 +700,13 @@ private void onInvokeResponse(NetworkMessage response, 
Long correlationId) {
         TimeoutObjectImpl responseFuture = requestsMap.remove(correlationId);
 
         if (responseFuture != null) {
-            responseFuture.future().complete(response);
+            var fut = responseFuture.future();
+
+            if (fut.isCompletedExceptionally()) {
+                metrics.incrementInvokeTimeouts();
+            } else {
+                fut.complete(response);
+            }

Review Comment:
   If I understand correctly, this is what happens when a node `A` wants to 
invoke a request on node `B`:
   1. `A` generates a correlation ID and stores a timeout object `T` in its 
requests map against this ID. A completable future that would contain the 
result of the request invocation is also passed into `T`. `A` contains a 
timeout worker that repeatedly loops over entries in the requests map and 
inspects the timeout objects contained therein. For any object whose time has 
lapsed, it marks its encapsulated response future as _completed exceptionally_. 
This could, in our example, potentially happen to `T`.
   2. `A` sends an _invoke_ request to `B`.
   3. Upon receiving a response from `B`, `A` pulls the timeout object `T` from 
the request map, and marks it as complete, using the response received. This is 
what happens in the original code for the snippet above, before I added my 
check. At this point, when the future is marked as complete using the response 
from `B`, a timeout may have already occurred, and the response may have 
already been marked as _completed exceptionally_ by the timeout worker. In such 
a case, re-marking it as complete with the response results in a NOOP. It still 
remains _exceptionally completed_.
   
   Therefore, I believe my code, checking for exceptional completion first, and 
then marking it as normally complete, is correct.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to