anmolnar commented on a change in pull request #831: ZOOKEEPER-3286: xid 
wrap-around causes connection loss/segfault when hitting predefined XIDs
URL: https://github.com/apache/zookeeper/pull/831#discussion_r266697000
 
 

 ##########
 File path: zookeeper-client/zookeeper-client-c/src/mt_adaptor.c
 ##########
 @@ -502,13 +502,13 @@ int32_t fetch_and_add(volatile int32_t* operand, int 
incr)
 }
 
 // make sure the static xid is initialized before any threads started
-__attribute__((constructor)) int32_t get_xid()
+int32_t get_xid()
 {
-    static int32_t xid = -1;
-    if (xid == -1) {
-        xid = time(0);
-    }
-    return fetch_and_add(&xid,1);
+    static int32_t xid = 1;
+
+    // The XID returned should not be negative to avoid collisions
+    // with reserved XIDs, such as AUTH_XID or SET_WATCHES_XID.
+    return fetch_and_add(&xid,1) & ~(1<<31);
 
 Review comment:
   This will return `0` when the overflow happens at the first time, so `xid == 
INT_MIN`, right?
   Which is not consistent with the single threaded case where we restart xid 
from 1 (similarly to the java client).
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to