Browse Source

ZOOKEEPER-4810: Fix buf data race at format_endpoint_info

ZOOKEEPER-4810: Fix buf data race at format_endpoint_info()
format_endpoint_info() is widely called in the IO thread. And the
some ZOOAPIs will call this method too: zoo_cycle_next_server()
and zoo_get_current_server(). These APIs return the same static buffer
read/write by IO thread causes data race.
Reviewers: kezhuw
Author: fanyang89
Closes #2140 from fanyang89/fix-c-client-format-endpoint-race
fanyang 3 weeks ago
parent
commit
f6766eca95
1 changed files with 2 additions and 2 deletions
  1. 2 2
      zookeeper-client/zookeeper-client-c/src/zookeeper.c

+ 2 - 2
zookeeper-client/zookeeper-client-c/src/zookeeper.c

@@ -5121,11 +5121,11 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
 
 
 static const char* format_endpoint_info(const struct sockaddr_storage* ep)
 static const char* format_endpoint_info(const struct sockaddr_storage* ep)
 {
 {
-    static char buf[134] = { 0 };
+    static __thread char buf[134] = { 0 };
     char addrstr[INET6_ADDRSTRLEN] = { 0 };
     char addrstr[INET6_ADDRSTRLEN] = { 0 };
     const char *fmtstring;
     const char *fmtstring;
     void *inaddr;
     void *inaddr;
-    char is_inet6 = 0;  // poor man's boolean
+    char is_inet6 = 0; // poor man's boolean
 #ifdef _WIN32
 #ifdef _WIN32
     char * addrstring;
     char * addrstring;
 #endif
 #endif