Skip to content

Commit 7112775

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 0b821b8 commit 7112775

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)) ||
@@ -1111,7 +1115,11 @@ initialize_SSL(PGconn *conn)
11111115
*/
11121116
#ifdef ENABLE_THREAD_SAFETY
11131117
if (pthread_mutex_lock(&ssl_config_mutex))
1118+
{
1119+
printfPQExpBuffer(&conn->errorMessage,
1120+
libpq_gettext("unable to acquire mutex\n"));
11141121
return -1;
1122+
}
11151123
#endif
11161124
if (SSL_CTX_use_certificate_chain_file(SSL_context, fnbuf) != 1)
11171125
{
@@ -1325,7 +1333,11 @@ initialize_SSL(PGconn *conn)
13251333

13261334
#ifdef ENABLE_THREAD_SAFETY
13271335
if (pthread_mutex_lock(&ssl_config_mutex))
1336+
{
1337+
printfPQExpBuffer(&conn->errorMessage,
1338+
libpq_gettext("unable to acquire mutex\n"));
13281339
return -1;
1340+
}
13291341
#endif
13301342
if (SSL_CTX_load_verify_locations(SSL_context, fnbuf, NULL) != 1)
13311343
{

0 commit comments

Comments
 (0)