fix: correct lock unlock order in Authentication classes

Fix lock order reversal in MySQL_Authentication,
ClickHouse_Authentication, and PgSQL_Authentication.

In memory_usage() and dump_all_users(), locks were acquired in order
(frontends, backends) but released in the same order instead of the
reverse. This creates a potential deadlock if another thread attempts
to acquire the same locks in opposite order.

Swap unlock calls to release backends before frontends, matching the
reverse of the acquisition order.
pull/5739/head
Rene Cannao 1 month ago
parent 65c522e635
commit 6cdd4e697e

@ -210,11 +210,11 @@ int ClickHouse_Authentication::dump_all_users(ch_account_details_t ***ads, bool
*ads=_ads;
__exit_dump_all_users:
#ifdef PROXYSQL_AUTH_PTHREAD_MUTEX
pthread_rwlock_unlock(&creds_frontends.lock);
pthread_rwlock_unlock(&creds_backends.lock);
pthread_rwlock_unlock(&creds_frontends.lock);
#else
spin_rdunlock(&creds_frontends.lock);
spin_rdunlock(&creds_backends.lock);
spin_rdunlock(&creds_frontends.lock);
#endif
return total_size;
}

@ -306,11 +306,11 @@ unsigned int MySQL_Authentication::memory_usage() {
ret += sizeof(PtrArray);
ret += (creds_backends.cred_array->size * sizeof(void *));
#ifdef PROXYSQL_AUTH_PTHREAD_MUTEX
pthread_rwlock_unlock(&creds_frontends.lock);
pthread_rwlock_unlock(&creds_backends.lock);
pthread_rwlock_unlock(&creds_frontends.lock);
#else
spin_rdunlock(&creds_frontends.lock);
spin_rdunlock(&creds_backends.lock);
spin_rdunlock(&creds_frontends.lock);
#endif
return ret;
}
@ -392,11 +392,11 @@ int MySQL_Authentication::dump_all_users(account_details_t ***ads, bool _complet
*ads=_ads;
__exit_dump_all_users:
#ifdef PROXYSQL_AUTH_PTHREAD_MUTEX
pthread_rwlock_unlock(&creds_frontends.lock);
pthread_rwlock_unlock(&creds_backends.lock);
pthread_rwlock_unlock(&creds_frontends.lock);
#else
spin_rdunlock(&creds_frontends.lock);
spin_rdunlock(&creds_backends.lock);
spin_rdunlock(&creds_frontends.lock);
#endif
return total_size;
}

@ -250,11 +250,11 @@ unsigned int PgSQL_Authentication::memory_usage() {
ret += sizeof(PtrArray);
ret += (creds_backends.cred_array->size * sizeof(void *));
#ifdef PROXYSQL_AUTH_PTHREAD_MUTEX
pthread_rwlock_unlock(&creds_frontends.lock);
pthread_rwlock_unlock(&creds_backends.lock);
pthread_rwlock_unlock(&creds_frontends.lock);
#else
spin_rdunlock(&creds_frontends.lock);
spin_rdunlock(&creds_backends.lock);
spin_rdunlock(&creds_frontends.lock);
#endif
return ret;
}
@ -327,11 +327,11 @@ int PgSQL_Authentication::dump_all_users(pgsql_account_details_t***ads, bool _co
*ads=_ads;
__exit_dump_all_users:
#ifdef PROXYSQL_AUTH_PTHREAD_MUTEX
pthread_rwlock_unlock(&creds_frontends.lock);
pthread_rwlock_unlock(&creds_backends.lock);
pthread_rwlock_unlock(&creds_frontends.lock);
#else
spin_rdunlock(&creds_frontends.lock);
spin_rdunlock(&creds_backends.lock);
spin_rdunlock(&creds_frontends.lock);
#endif
return total_size;
}

Loading…
Cancel
Save