Skip to content

Commit 1e8e324

Browse files
committed
Improve handling of pthread_mutex_lock error case
We should really be reporting a useful error along with returning a valid return code if pthread_mutex_lock() throws an error for some reason. Add that and back-patch to 9.0 as the prior patch. Pointed out by Alvaro Herrera
1 parent 9d7f66b commit 1e8e324

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/interfaces/libpq/fe-secure.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,11 @@ pqsecure_open_client(PGconn *conn)
262262

263263
#ifdef ENABLE_THREAD_SAFETY
264264
if (pthread_mutex_lock(&ssl_config_mutex))
265-
return -1;
265+
{
266+
printfPQExpBuffer(&conn->errorMessage,
267+
libpq_gettext("unable to acquire mutex\n"));
268+
return PGRES_POLLING_FAILED;
269+
}
266270
#endif
267271
/* Create a connection-specific SSL object */
268272
if (!(conn->ssl = SSL_new(SSL_context)) ||
@@ -1113,7 +1117,11 @@ initialize_SSL(PGconn *conn)
11131117
*/
11141118
#ifdef ENABLE_THREAD_SAFETY
11151119
if (pthread_mutex_lock(&ssl_config_mutex))
1120+
{
1121+
printfPQExpBuffer(&conn->errorMessage,
1122+
libpq_gettext("unable to acquire mutex\n"));
11161123
return -1;
1124+
}
11171125
#endif
11181126
if (SSL_CTX_use_certificate_chain_file(SSL_context, fnbuf) != 1)
11191127
{
@@ -1327,7 +1335,11 @@ initialize_SSL(PGconn *conn)
13271335

13281336
#ifdef ENABLE_THREAD_SAFETY
13291337
if (pthread_mutex_lock(&ssl_config_mutex))
1338+
{
1339+
printfPQExpBuffer(&conn->errorMessage,
1340+
libpq_gettext("unable to acquire mutex\n"));
13301341
return -1;
1342+
}
13311343
#endif
13321344
if (SSL_CTX_load_verify_locations(SSL_context, fnbuf, NULL) != 1)
13331345
{

0 commit comments

Comments
 (0)