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

 ##########
 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:
   Sorry for the delay. I just updated the patch such that for the single 
threaded version of get_xid we now reset the xid counter to 1 if a previous 
increment has caused an overflow.

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