devabhishekpal commented on code in PR #1363:
URL: https://github.com/apache/ratis/pull/1363#discussion_r2914633600


##########
ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcLogAppender.java:
##########
@@ -366,16 +382,73 @@ void onNext(AppendEntriesRequestProto proto)
       while (!stream.isReady() && running) {
         sleep(waitForReady, isHeartBeat);
       }
-      stream.onNext(proto);
+      try {
+        stream.onNext(proto);
+      } catch (Exception e) {
+        InterruptedIOException ioe =
+            new InterruptedIOException("Failed to send request via stream");
+        ioe.initCause(e);
+        throw ioe;
+      }
     }
 
     void stop() {
       running = false;
     }
 
     void onCompleted() {
-      appendLog.onCompleted();
-      Optional.ofNullable(heartbeat).ifPresent(StreamObserver::onCompleted);
+      if (completed.compareAndSet(false, true)) {
+        completeStreamGracefully(appendLog, "appendLog");
+        Optional.ofNullable(heartbeat)
+            .ifPresent(s -> completeStreamGracefully(s, "heartbeat"));
+      }
+      final long delayMs = Math.max(1L, 
completeGracePeriod.toLong(TimeUnit.MILLISECONDS));
+      closer.schedule(this::cancelIfStillNeeded, delayMs, 
TimeUnit.MILLISECONDS);

Review Comment:
   This schedules `cancelIfStillNeeded()` outside the 
`completed.compareAndSet(...)` block. Repeated onCompleted() calls can queue 
redundant cancel tasks.
   
   Can this be avoided?
   Also I think if it’s invoked again after `shutdownCloser()` it may throw 
exception.



-- 
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