@@ -42,32 +42,34 @@ constexpr size_t MAX_ISSUER_MUTEXES = 1000;
4242// Get or create a mutex for a specific issuer
4343std::shared_ptr<std::mutex> get_issuer_mutex (const std::string &issuer) {
4444 std::lock_guard<std::mutex> guard (issuer_mutex_map_lock);
45-
45+
4646 auto it = issuer_mutexes.find (issuer);
4747 if (it != issuer_mutexes.end ()) {
4848 return it->second ;
4949 }
50-
50+
5151 // Prevent resource exhaustion: limit the number of cached mutexes
5252 if (issuer_mutexes.size () >= MAX_ISSUER_MUTEXES) {
5353 // Remove mutexes that are no longer in use
5454 // Since we hold issuer_mutex_map_lock, no other thread can acquire
5555 // a reference to these mutexes, making this check safe
56- for (auto iter = issuer_mutexes.begin (); iter != issuer_mutexes.end (); ) {
56+ for (auto iter = issuer_mutexes.begin ();
57+ iter != issuer_mutexes.end ();) {
5758 if (iter->second .use_count () == 1 ) {
5859 // Only we hold a reference, safe to remove
5960 iter = issuer_mutexes.erase (iter);
6061 } else {
6162 ++iter;
6263 }
6364 }
64-
65+
6566 // If still at capacity after cleanup, fail rather than unbounded growth
6667 if (issuer_mutexes.size () >= MAX_ISSUER_MUTEXES) {
67- throw std::runtime_error (" Too many concurrent issuers - resource exhaustion prevented" );
68+ throw std::runtime_error (
69+ " Too many concurrent issuers - resource exhaustion prevented" );
6870 }
6971 }
70-
72+
7173 auto mutex_ptr = std::make_shared<std::mutex>();
7274 issuer_mutexes[issuer] = mutex_ptr;
7375 return mutex_ptr;
0 commit comments