Skip to content

Commit d0fcfb9

Browse files
fanyang89meszinorbi
authored andcommitted
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
1 parent 4495456 commit d0fcfb9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

zookeeper-client/zookeeper-client-c/src/zookeeper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5121,11 +5121,11 @@ int zoo_add_auth(zhandle_t *zh,const char* scheme,const char* cert,
51215121

51225122
static const char* format_endpoint_info(const struct sockaddr_storage* ep)
51235123
{
5124-
static char buf[134] = { 0 };
5124+
static __thread char buf[134] = { 0 };
51255125
char addrstr[INET6_ADDRSTRLEN] = { 0 };
51265126
const char *fmtstring;
51275127
void *inaddr;
5128-
char is_inet6 = 0; // poor man's boolean
5128+
char is_inet6 = 0; // poor man's boolean
51295129
#ifdef _WIN32
51305130
char * addrstring;
51315131
#endif

0 commit comments

Comments
 (0)