Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8359ed8

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 f31c149 commit 8359ed8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/interfaces/libpq/fe-secure.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ pqsecure_open_client(PGconn *conn)
261261

262262
#ifdef ENABLE_THREAD_SAFETY
263263
if (pthread_mutex_lock(&ssl_config_mutex))
264-
return -1;
264+
{
265+
printfPQExpBuffer(&conn->errorMessage,
266+
libpq_gettext("unable to acquire mutex\n"));
267+
return PGRES_POLLING_FAILED;
268+
}
265269
#endif
266270
/* Create a connection-specific SSL object */
267271
if (!(conn->ssl = SSL_new(SSL_context)) ||
@@ -1112,7 +1116,11 @@ initialize_SSL(PGconn *conn)
11121116
*/
11131117
#ifdef ENABLE_THREAD_SAFETY
11141118
if (pthread_mutex_lock(&ssl_config_mutex))
1119+
{
1120+
printfPQExpBuffer(&conn->errorMessage,
1121+
libpq_gettext("unable to acquire mutex\n"));
11151122
return -1;
1123+
}
11161124
#endif
11171125
if (SSL_CTX_use_certificate_chain_file(SSL_context, fnbuf) != 1)
11181126
{
@@ -1326,7 +1334,11 @@ initialize_SSL(PGconn *conn)
13261334

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

0 commit comments

Comments
 (0)