Skip to content

Commit

Permalink
Remove lockless peak from sessions managment
Browse files Browse the repository at this point in the history
We will always pay the price of a lock, but this is the more robust
thing to do for now.

Fixes:
 CID 468681
 CID 468678

Signed-off-by: Simo Sorce <simo@redhat.com>
  • Loading branch information
simo5 committed Nov 28, 2023
1 parent d5aeab4 commit 2e2c187
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,22 +957,16 @@ void p11prov_return_session(P11PROV_SESSION *session)
pool = session->pool;

if (pool) {
/* peek at the pool lockless worst case we waste some time */
if (pool->open_sessions >= pool->max_cached_sessions) {
/* not much we can do if this fails,
* but only accounting will be a bit off */

/* LOCKED SECTION ------------- */
if (MUTEX_LOCK(pool) == CKR_OK) {
if (pool->open_sessions >= pool->max_cached_sessions
&& session != pool->login_session) {
token_session_close(session);
pool->open_sessions--;
}
(void)MUTEX_UNLOCK(pool);
/* LOCKED SECTION ------------- */
if (MUTEX_LOCK(pool) == CKR_OK) {
if (pool->open_sessions >= pool->max_cached_sessions
&& session != pool->login_session) {
token_session_close(session);
pool->open_sessions--;
}
/* ------------- LOCKED SECTION */
(void)MUTEX_UNLOCK(pool);
}
/* ------------- LOCKED SECTION */
}

ret = MUTEX_LOCK(session);
Expand Down

0 comments on commit 2e2c187

Please sign in to comment.