zookeeper-dev mailing list archives

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

 ##########
 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 realize this will sound very boring but why not just reset xid to 1 prior to it rolling
over? a) the xid actually represents the next xid to send and b) much easier to read/grok
for someone new to the code.

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