Skip to content

Commit fb40b28

Browse files
committed
session server ch BUGFIX check ch thread running
When ch sess is established, only the status of the sess was checked in a loop, which isn't enough when we just delete a CH client from the config without the client gracefully closing first.
1 parent 731bd65 commit fb40b28

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

src/session_server.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,35 @@ nc_server_ch_client_get_idle_timeout(const char *client_name, uint32_t *idle_tim
32983298
return ret;
32993299
}
33003300

3301+
/**
3302+
* @brief Checks if a Call Home thread should terminate.
3303+
*
3304+
* Checks the shared boolean variable thread_running. This should be done everytime
3305+
* before entering a critical section.
3306+
*
3307+
* @param[in] data Call Home thread's data.
3308+
*
3309+
* @return 0 if the thread should stop running, -1 if it can continue.
3310+
*/
3311+
static int
3312+
nc_server_ch_client_thread_is_running(struct nc_server_ch_thread_arg *data)
3313+
{
3314+
int ret = -1;
3315+
3316+
/* COND LOCK */
3317+
if (nc_mutex_lock(&data->cond_lock, NC_CH_COND_LOCK_TIMEOUT, __func__) != 1) {
3318+
return ret;
3319+
}
3320+
if (!data->thread_running) {
3321+
/* thread should stop running */
3322+
ret = 0;
3323+
}
3324+
/* COND UNLOCK */
3325+
nc_mutex_unlock(&data->cond_lock, __func__);
3326+
3327+
return ret;
3328+
}
3329+
33013330
/**
33023331
* @brief Wait for any event after a NC session was established on a CH client.
33033332
*
@@ -3392,7 +3421,7 @@ nc_server_ch_client_thread_session_cond_wait(struct nc_server_ch_thread_arg *dat
33923421
session->status = NC_STATUS_INVALID;
33933422
session->term_reason = NC_SESSION_TERM_TIMEOUT;
33943423
}
3395-
} while (session->status == NC_STATUS_RUNNING);
3424+
} while ((session->status == NC_STATUS_RUNNING) && nc_server_ch_client_thread_is_running(data));
33963425
/* broke out of the loop, but still holding the ch_lock */
33973426

33983427
/* signal to nc_session_free() that CH thread is terminating */
@@ -3450,35 +3479,6 @@ nc_server_ch_client_thread_is_running_wait(struct nc_session *session, struct nc
34503479
return ret;
34513480
}
34523481

3453-
/**
3454-
* @brief Checks if a Call Home thread should terminate.
3455-
*
3456-
* Checks the shared boolean variable thread_running. This should be done everytime
3457-
* before entering a critical section.
3458-
*
3459-
* @param[in] data Call Home thread's data.
3460-
*
3461-
* @return 0 if the thread should stop running, -1 if it can continue.
3462-
*/
3463-
static int
3464-
nc_server_ch_client_thread_is_running(struct nc_server_ch_thread_arg *data)
3465-
{
3466-
int ret = -1;
3467-
3468-
/* COND LOCK */
3469-
if (nc_mutex_lock(&data->cond_lock, NC_CH_COND_LOCK_TIMEOUT, __func__) != 1) {
3470-
return ret;
3471-
}
3472-
if (!data->thread_running) {
3473-
/* thread should stop running */
3474-
ret = 0;
3475-
}
3476-
/* COND UNLOCK */
3477-
nc_mutex_unlock(&data->cond_lock, __func__);
3478-
3479-
return ret;
3480-
}
3481-
34823482
/**
34833483
* @brief Wait for a Call Home client to have at least one endpoint defined.
34843484
*

0 commit comments

Comments
 (0)