eolivelli commented on a change in pull request #1301: ZOOKEEPER-3774: Close 
quorum socket asynchronously on the leader to a…
URL: https://github.com/apache/zookeeper/pull/1301#discussion_r407040000
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/LearnerHandler.java
 ##########
 @@ -1150,4 +1140,33 @@ public void setFirstPacket(boolean value) {
         needOpPacket = value;
     }
 
+    void closeSocket() {
+        if (sock != null && !sock.isClosed() && 
sockBeingClosed.compareAndSet(false, true)) {
+            LOG.error("Unexpected exception causing shutdown while sock is 
still open");
+
+            if (closeSocketAsync) {
+                closeSockAsync();
+            } else {
+                closeSockSync();
+            }
+        }
+    }
+
+    void closeSockAsync() {
+        final Thread closingThread = new Thread(() -> closeSockSync(), 
"CloseSocketThread(sid:" + this.sid);
+        closingThread.setDaemon(true);
+        closingThread.start();
+    }
+
+    void closeSockSync() {
+        try {
+            if (sock != null) {
+                long startTime = Time.currentElapsedTime();
+                sock.close();
+                
ServerMetrics.getMetrics().SOCKET_CLOSING_TIME.add(Time.currentElapsedTime() - 
startTime);
 
 Review comment:
   would it be useful to record this value even in case of failure ?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to