Skip to content

Commit 8b4f936

Browse files
committed
session BUGFIX issues with timed locks
1 parent f056e9d commit 8b4f936

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/session.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -912,15 +912,18 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
912912
}
913913

914914
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
915-
/* CH LOCK */
916-
nc_mutex_lock(&session->opts.server.ch_lock, NC_SESSION_CH_LOCK_TIMEOUT, __func__);
915+
/* CH LOCK, continue on error */
916+
r = nc_mutex_lock(&session->opts.server.ch_lock, NC_SESSION_CH_LOCK_TIMEOUT, __func__);
917917
}
918918

919919
status = session->status;
920920

921921
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
922922
/* CH UNLOCK */
923-
nc_mutex_unlock(&session->opts.server.ch_lock, __func__);
923+
if (!r) {
924+
/* only if we locked it */
925+
nc_mutex_unlock(&session->opts.server.ch_lock, __func__);
926+
}
924927
}
925928

926929
if (status == NC_STATUS_CLOSING) {

src/session_client.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,7 @@ nc_client_monitoring_thread(void *arg)
34193419

34203420
next_iter:
34213421
/* UNLOCK */
3422-
pthread_mutex_unlock(&mtarg->lock);
3422+
nc_mutex_unlock(&client_opts.monitoring_thread_data.lock, __func__);
34233423
locked = 0;
34243424

34253425
/* if an event occurred, call the callback */
@@ -3440,7 +3440,7 @@ nc_client_monitoring_thread(void *arg)
34403440
cleanup:
34413441
if (locked) {
34423442
/* UNLOCK */
3443-
pthread_mutex_unlock(&mtarg->lock);
3443+
nc_mutex_unlock(&client_opts.monitoring_thread_data.lock, __func__);
34443444
}
34453445
VRB(NULL, "Client monitoring thread exit.");
34463446
return NULL;
@@ -3524,7 +3524,7 @@ nc_client_monitoring_thread_stop(void)
35243524
}
35253525

35263526
/* UNLOCK */
3527-
pthread_mutex_unlock(&mtarg->lock);
3527+
nc_mutex_unlock(&client_opts.monitoring_thread_data.lock, __func__);
35283528

35293529
r = pthread_join(tid, NULL);
35303530
if (r) {
@@ -3550,7 +3550,7 @@ nc_client_monitoring_thread_stop(void)
35503550
mtarg->pfds = NULL;
35513551

35523552
/* UNLOCK */
3553-
pthread_mutex_unlock(&mtarg->lock);
3553+
nc_mutex_unlock(&client_opts.monitoring_thread_data.lock, __func__);
35543554
}
35553555

35563556
API void

src/session_server.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,9 @@ nc_ps_poll_sess(struct nc_ps_session *ps_session, time_t now_mono)
22192219

22202220
/* CONFIG READ LOCK */
22212221
if (nc_rwlock_lock(&server_opts.config_lock, NC_RWLOCK_READ, NC_CONFIG_LOCK_TIMEOUT, __func__) != 1) {
2222+
ps_session->state = NC_PS_STATE_NONE;
22222223
ret = NC_PSPOLL_ERROR;
2224+
break;
22232225
} else {
22242226
ret = nc_ps_poll_session_io(ps_session->session, NC_SESSION_LOCK_TIMEOUT, now_mono, msg);
22252227
/* CONFIG UNLOCK */
@@ -4358,7 +4360,10 @@ nc_server_notif_cert_exp_thread(void *arg)
43584360
/* config changed, reload the certificates and intervals */
43594361
nc_server_notif_cert_exp_data_destroy(exp_dates, exp_date_count, intervals);
43604362

4361-
nc_server_notif_cert_exp_intervals_get(default_intervals, 3, &intervals, &interval_count);
4363+
r = nc_server_notif_cert_exp_intervals_get(default_intervals, 3, &intervals, &interval_count);
4364+
if (r) {
4365+
break;
4366+
}
43624367

43634368
r = nc_server_notif_cert_exp_dates_get(intervals, interval_count, &exp_dates, &exp_date_count);
43644369
if (r) {

0 commit comments

Comments
 (0)