Skip to content

Commit

Permalink
Switch static variable to thread_local to fix underflow bug
Browse files Browse the repository at this point in the history
Multiple threads appear to be running through `read_callback` with their own data, and
they're fighting over the `sentSoFar` variable. Switching it from static to thread_local
makes sure each thread has its own copy to use.
  • Loading branch information
jhiemstrawisc committed Apr 26, 2024
1 parent 7a47341 commit 1db36dd
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ int debug_callback(CURL *, curl_infotype ci, char *data, size_t size, void *) {
}

size_t read_callback(char *buffer, size_t size, size_t n, void *v) {
// This can be static because only one curl_easy_perform() can be
// running at a time.
static size_t sentSoFar = 0;
thread_local size_t sentSoFar = 0;
std::string *payload = (std::string *)v;

if (sentSoFar == payload->size()) {
Expand Down

0 comments on commit 1db36dd

Please sign in to comment.