zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] ccma14 commented on a change in pull request #831: ZOOKEEPER-3286: xid wrap-around causes connection loss/segfault when hitting predefined XIDs
Date Tue, 19 Mar 2019 01:26:58 GMT
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_r266701482
 
 

 ##########
 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:
   You are correct. -- The first revision of the patch had behavior (and code) that was symmetric
between ST/MT. -- I looked at the code (and ran some tests) and there is nothing special about
XID being 0 in the C client.
   
   I think at this point we have two options:
   
   1) reset XID to 0 instead of 1 in the ST version of the code. This would give you symmetric
behavior (even tho the code no longer looks symmetric).
   
   2) If there is some opposition against ever having 0 returned, I can modify the MT code
such that if you were about to return 0, you do another fetch and add. Something like:
   
       result = 0;
       while (result == 0) {
           result = fetch_and_add(&xid,1) & ~(1<<31);
       }
       return result;
   
   Please LMK what your preference is. IMHO none of the two solutions proposed has a correctness
issue.

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


With regards,
Apache Git Services

Mime
View raw message