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_r264450447
 
 

 ##########
 File path: zookeeper-client/zookeeper-client-c/src/st_adaptor.c
 ##########
 @@ -77,11 +77,11 @@ int32_t inc_ref_counter(zhandle_t* zh,int i)
 
 int32_t get_xid()
 {
-    static int32_t xid = -1;
-    if (xid == -1) {
-        xid = time(0);
-    }
-    return xid++;
+    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 xid++ & ~(1<<31);
 
 Review comment:
   I'm not a C expert, but I believe C coders generally prefer magic bitwise 
operations to gain performance.

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