Dead lock with log4cplus

I have a method doing a database connection loop, that calls every 2 seconds this next piece of code until being successful:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>166 try {
167 this->conn = new pqxx::connection(psqlConnectionString);
168 }
169 catch(const exception &ex) {
170 char message[5000];
171 sprintf(message, "Cannot connect to the database %s on host %s:%s as %s: %s", dbname.c_str(), hostname.c_str(), port.c_str(), username.c_str(), ex.what());
172 LOG4CPLUS_ERROR(_logger, message);
173
174 char message2[5000];
175 sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str());
176 LOG4CPLUS_ERROR(_logger, message2);
177 throw invalid_argument(message2);
178 }
</code>
<code>166 try { 167 this->conn = new pqxx::connection(psqlConnectionString); 168 } 169 catch(const exception &ex) { 170 char message[5000]; 171 sprintf(message, "Cannot connect to the database %s on host %s:%s as %s: %s", dbname.c_str(), hostname.c_str(), port.c_str(), username.c_str(), ex.what()); 172 LOG4CPLUS_ERROR(_logger, message); 173 174 char message2[5000]; 175 sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str()); 176 LOG4CPLUS_ERROR(_logger, message2); 177 throw invalid_argument(message2); 178 } </code>
166    try {
167        this->conn = new pqxx::connection(psqlConnectionString);
168    }
169    catch(const exception &ex) {
170        char message[5000];
171        sprintf(message, "Cannot connect to the database %s on host %s:%s as %s: %s", dbname.c_str(), hostname.c_str(), port.c_str(), username.c_str(), ex.what());
172        LOG4CPLUS_ERROR(_logger, message);
173
174        char message2[5000];
175        sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str());
176        LOG4CPLUS_ERROR(_logger, message2);
177        throw invalid_argument(message2);
178    }

How the method succeeds or fails to connect ins’t important.
What is, is that the log4cplus 2.1.1 _logger makes eventually my program hanging (I don’t think it can be sprintf). And I cannot enter in debug mode into it easily.

In the following logs, you can see in my program logging that it logs at these statements:
db_adapter.cpp 172, 176, 56, 26,
db_adapter.cpp 172, 176, 56, 26,
db_adapter.cpp 172
then it hangs.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>a_cpp_template | [INFO ][07/10/24 09:05:46,110][/tmp/cpp-app/src/adapters/app.cpp:31] 2/6 - Starting DB Adapter
a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template | Is the server running on that host and accepting TCP/IP connections?
a_cpp_template |
a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template | Is the server running on that host and accepting TCP/IP connections?
a_cpp_template |
a_cpp_template | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd'
a_cpp_template | [ERROR][07/10/24 09:05:50,117][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template | Is the server running on that host and accepting TCP/IP connections?
[...and then a_cpp_template is never heard again...]
</code>
<code>a_cpp_template | [INFO ][07/10/24 09:05:46,110][/tmp/cpp-app/src/adapters/app.cpp:31] 2/6 - Starting DB Adapter a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused a_cpp_template | Is the server running on that host and accepting TCP/IP connections? a_cpp_template | a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused a_cpp_template | Is the server running on that host and accepting TCP/IP connections? a_cpp_template | a_cpp_template | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was: a_cpp_template | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' a_cpp_template | [ERROR][07/10/24 09:05:50,117][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused a_cpp_template | Is the server running on that host and accepting TCP/IP connections? [...and then a_cpp_template is never heard again...] </code>
a_cpp_template       | [INFO ][07/10/24 09:05:46,110][/tmp/cpp-app/src/adapters/app.cpp:31] 2/6 - Starting DB Adapter
a_cpp_template       | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template       |  Is the server running on that host and accepting TCP/IP connections?
a_cpp_template       | 
a_cpp_template       | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:46,113][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template       |  Is the server running on that host and accepting TCP/IP connections?
a_cpp_template       | 
a_cpp_template       | [ERROR][07/10/24 09:05:48,114][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:176] whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:56] Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:48,115][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:26] Next attempt in 2 seconds, as attempt to connect to database failed! Aborting transaction and/or connection in response of previous exception received: whole param string was:
a_cpp_template       | user='cdp_template_manager_owner_user' host='cdp-database' port='5432' dbname='template_manager' sslmode='require' password='cdp_template_manager_pwd' 
a_cpp_template       | [ERROR][07/10/24 09:05:50,117][/tmp/cpp-app/src/adapters/dbadapter/db_adapter.cpp:172] Cannot connect to the database template_manager on host cdp-database:5432 as cdp_template_manager_owner_user: connection to server at "cdp-database" (172.18.0.2), port 5432 failed: Connection refused
a_cpp_template       |  Is the server running on that host and accepting TCP/IP connections?

[...and then a_cpp_template is never heard again...]

In the following part of my code:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>172 LOG4CPLUS_ERROR(_logger, message);
173
174 char message2[5000];
175 sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str());
176 LOG4CPLUS_ERROR(_logger, message2);
</code>
<code>172 LOG4CPLUS_ERROR(_logger, message); 173 174 char message2[5000]; 175 sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str()); 176 LOG4CPLUS_ERROR(_logger, message2); </code>
172        LOG4CPLUS_ERROR(_logger, message);
173
174        char message2[5000];
175        sprintf(message2, "whole param string was:n%s", psqlConnectionString.c_str());
176        LOG4CPLUS_ERROR(_logger, message2);

what might prevent it going from line 172 (that was executed, I can see it in the logs) to 176 one, it never joined? I wonder.

I’ve investigated around _logger here, and found that it was declared in another class, as a global variable like that:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>log4cplus::Logger _logger;
void log4cplus::initialise()
{
::log4cplus::initialize();
log4cplus::PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("./src/utils/custom-logger/log4cpp.properties"));
_logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
}
</code>
<code>log4cplus::Logger _logger; void log4cplus::initialise() { ::log4cplus::initialize(); log4cplus::PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("./src/utils/custom-logger/log4cpp.properties")); _logger = Logger::getInstance(LOG4CPLUS_TEXT("main")); } </code>
log4cplus::Logger _logger; 

void log4cplus::initialise()
{
    ::log4cplus::initialize();
    log4cplus::PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT("./src/utils/custom-logger/log4cpp.properties"));

    _logger = Logger::getInstance(LOG4CPLUS_TEXT("main"));
}

Is such initialization trouble prone?
What can cause an dead lock?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật