FS-10167: Fixed sessions to cleanup external from their own state processing thread to avoid deadlocking on thread join during cleanup.

This commit is contained in:
Shane Bryldt 2017-04-04 12:47:14 -06:00
parent dd6031544a
commit dbd2ef2d8b
3 changed files with 19 additions and 2 deletions

View File

@ -505,8 +505,7 @@ ks_status_t blade_session_state_on_destroy(blade_session_t *bs)
ks_log(KS_LOG_DEBUG, "Session (%s) state destroy\n", bs->id);
blade_handle_sessions_remove(bs);
blade_session_destroy(&bs);
blade_session_state_set(bs, BLADE_SESSION_STATE_CLEANUP);
// @todo ignoring returns for now, see what makes sense later
return KS_STATUS_SUCCESS;

View File

@ -889,6 +889,7 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data)
{
blade_handle_t *bh = NULL;
blade_connection_t *bc = NULL;
blade_session_t *bs = NULL;
ks_hash_iterator_t *it = NULL;
ks_q_t *cleanup = NULL;
@ -917,6 +918,22 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data)
blade_connection_destroy(&bc);
}
ks_hash_write_lock(bh->sessions);
for (it = ks_hash_first(bh->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
void *key = NULL;
blade_session_t *value = NULL;
ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
if (blade_session_state_get(value) == BLADE_SESSION_STATE_CLEANUP) ks_q_push(cleanup, value);
}
ks_hash_write_unlock(bh->sessions);
while (ks_q_trypop(cleanup, (void **)&bs) == KS_STATUS_SUCCESS) {
blade_handle_sessions_remove(bs);
blade_session_destroy(&bs);
}
ks_sleep_ms(500);
}

View File

@ -105,6 +105,7 @@ typedef enum {
typedef enum {
BLADE_SESSION_STATE_NONE,
BLADE_SESSION_STATE_CLEANUP,
BLADE_SESSION_STATE_DESTROY,
BLADE_SESSION_STATE_HANGUP,
BLADE_SESSION_STATE_CONNECT,