# HG changeset patch # User Alain Mazy # Date 1786373581 -7200 # Node ID dbad0dbcbbc3564f9807e364480c9ea1d49a230a # Parent dca83277bdde846c5ad35a05428f5943c2be8710 make sure we don't reused HTTP-XX thread names after a call to /tools/reset diff -r dca83277bdde -r dbad0dbcbbc3 OrthancFramework/Sources/HttpServer/HttpServer.cpp --- a/OrthancFramework/Sources/HttpServer/HttpServer.cpp Mon Aug 10 15:33:26 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.cpp Mon Aug 10 16:53:01 2026 +0200 @@ -1280,7 +1280,10 @@ struct mg_connection *connection, const struct mg_request_info *request) { - server.UpdateCurrentThreadName(); + // Since we don't control the thread creation ourselves, we set and clear + // the thread name everytime otherwise, the thread name will persist even + // after a call to /tools/reset and Orthanc would stop because the same thread name is used multiple times + Logging::ScopedCurrentThreadNameSetter setter(server.GetCurrentThreadName()); std::unique_ptr counter(server.CreateAvailableHttpThreadsDecounter()); @@ -2467,13 +2470,25 @@ } - void HttpServer::UpdateCurrentThreadName() + std::string HttpServer::GetCurrentThreadName() { // threads are created in CivetWeb -> assign them a name the first time they are used - if (!Logging::HasCurrentThreadName()) + boost::thread::id threadId = boost::this_thread::get_id(); + + boost::upgrade_lock readerLock(threadCounterMutex_); // reader lock to check if the threadId has already been registered + + if (threadNames_.find(threadId) == threadNames_.end()) { - boost::mutex::scoped_lock lock(threadCounterMutex_); - Logging::SetCurrentThreadName(std::string("HTTP-") + boost::lexical_cast(threadCounter_++)); + boost::upgrade_to_unique_lock writerLock(readerLock); + + std::string thisThreadName = std::string("HTTP-") + boost::lexical_cast(threadCounter_++); + threadNames_[threadId] = thisThreadName; + + return thisThreadName; + } + else + { + return threadNames_[threadId]; } } diff -r dca83277bdde -r dbad0dbcbbc3 OrthancFramework/Sources/HttpServer/HttpServer.h --- a/OrthancFramework/Sources/HttpServer/HttpServer.h Mon Aug 10 15:33:26 2026 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpServer.h Mon Aug 10 16:53:01 2026 +0200 @@ -54,6 +54,7 @@ #include #include #include +#include namespace Orthanc @@ -118,8 +119,9 @@ unsigned int requestTimeout_; // In seconds std::unique_ptr availableHttpThreadsMetrics_; // New in Orthanc 1.12.9 - boost::mutex threadCounterMutex_; // New in Orthanc 1.12.9 - uint16_t threadCounter_; // Introduced as a global, static variable in Orthanc 1.12.2 + boost::shared_mutex threadCounterMutex_; // protects threadCounter_ and threadNames_; + uint16_t threadCounter_; + std::map threadNames_; // New in Orthanc 1.12.11 bool hasMaxBodySize_; @@ -247,7 +249,7 @@ // Can return NULL if SetMetricsRegistry() was not call beforehand MetricsRegistry::AvailableResourcesDecounter* CreateAvailableHttpThreadsDecounter(); - void UpdateCurrentThreadName(); + std::string GetCurrentThreadName(); void SetMaxBodySize(uint64_t size);