From 1db36ddd8af5f7ece90d8d3a7a0d25c61b9fd030 Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Fri, 26 Apr 2024 14:44:53 +0000 Subject: [PATCH] Switch static variable to thread_local to fix underflow bug 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. --- src/HTTPCommands.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/HTTPCommands.cc b/src/HTTPCommands.cc index 361340e..3f23c67 100644 --- a/src/HTTPCommands.cc +++ b/src/HTTPCommands.cc @@ -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()) {