From ce5d5c5cfac141f39628af3e248b2ea470769d6f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 16 Jun 2020 19:59:44 +0200 Subject: [PATCH] Increased sleep max --- server/main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/main.cpp b/server/main.cpp index 81052b8..3fff787 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -456,19 +456,26 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_ int result, attempt{0}, sleep{5}; while((result = original_pthread_create(thread, attr, start_routine, arg)) != 0 && errno == EAGAIN) { - if(attempt > 50) { - std::cerr << "[CRITICAL] pthread_create(...) cause EAGAIN for the last 50 attempts! Aborting application execution!" << std::endl; + if(attempt > 55) { + std::cerr << "[CRITICAL] pthread_create(...) cause EAGAIN for the last 50 attempts (~4.7seconds)! Aborting application execution!" << std::endl; std::abort(); } else if(attempt > 5) { /* let some other threads do work */ pthread_yield(); + } else if(attempt == 0) { + std::string message{"[CRITICAL] Failed to spawn thread (Resource temporarily unavailable). Trying to recover."}; + std::cerr << message << std::endl; } - std::string message{"[CRITICAL] pthread_create(...) cause EAGAIN! Trying again in " + std::to_string(sleep) + "usec (Attempt: " + std::to_string(attempt) + ")"}; - std::cerr << message << std::endl; + //std::string message{"[CRITICAL] pthread_create(...) cause EAGAIN! Trying again in " + std::to_string(sleep) + "usec (Attempt: " + std::to_string(attempt) + ")"}; + //std::cerr << message << std::endl; usleep(sleep); attempt++; sleep = (int) (sleep * 1.25); } + if(attempt > 0) { + std::string message{"[CRITICAL] Successfully recovered from pthread_create() EAGAIN error. Took " + std::to_string(attempt) + " attempts."}; + std::cerr << message << std::endl; + } return result; } \ No newline at end of file