Skip to content

Commit feccb31

Browse files
committed
session BUGFIX timeout of CH session free
1 parent e08ed5e commit feccb31

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

src/session.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -741,26 +741,27 @@ nc_session_free(struct nc_session *session, void (*data_free)(void *))
741741
/* mark session for closing */
742742
session->status = NC_STATUS_CLOSING;
743743

744-
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
744+
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CH_THREAD)) {
745745
pthread_cond_signal(&session->opts.server.ch_cond);
746746

747747
nc_gettimespec_real(&ts);
748748
nc_addtimespec(&ts, NC_SESSION_FREE_LOCK_TIMEOUT);
749749

750750
/* wait for CH thread to actually wake up and terminate */
751751
r = 0;
752-
while (!r && (session->flags & NC_SESSION_CALLHOME)) {
752+
while (!r && (session->flags & NC_SESSION_CH_THREAD)) {
753753
r = pthread_cond_timedwait(&session->opts.server.ch_cond, &session->opts.server.ch_lock, &ts);
754754
}
755-
756-
/* CH UNLOCK */
757-
pthread_mutex_unlock(&session->opts.server.ch_lock);
758-
759755
if (r) {
760756
ERR(session, "Waiting for Call Home thread failed (%s).", strerror(r));
761757
}
762758
}
763759

760+
if ((session->side == NC_SERVER) && (session->flags & NC_SESSION_CALLHOME)) {
761+
/* CH UNLOCK */
762+
pthread_mutex_unlock(&session->opts.server.ch_lock);
763+
}
764+
764765
connected = nc_session_is_connected(session);
765766

766767
/* transport implementation cleanup */

src/session_p.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ struct nc_session {
432432
void *data; /**< arbitrary user data */
433433
uint8_t flags; /**< various flags of the session */
434434
#define NC_SESSION_SHAREDCTX 0x01
435-
#define NC_SESSION_CALLHOME 0x02
435+
#define NC_SESSION_CALLHOME 0x02 /**< session is Call Home and ch_lock is initialized */
436+
#define NC_SESSION_CH_THREAD 0x04 /**< protected by ch_lock */
436437

437438
union {
438439
struct {
@@ -446,7 +447,7 @@ struct nc_session {
446447

447448
/* client flags */
448449
/* some server modules failed to load so the data from them will be ignored - not use strict flag for parsing */
449-
# define NC_SESSION_CLIENT_NOT_STRICT 0x40
450+
# define NC_SESSION_CLIENT_NOT_STRICT 0x08
450451
} client;
451452
struct {
452453
/* server side only data */
@@ -465,13 +466,13 @@ struct nc_session {
465466
/* server flags */
466467
#ifdef NC_ENABLED_SSH
467468
/* SSH session authenticated */
468-
# define NC_SESSION_SSH_AUTHENTICATED 0x04
469+
# define NC_SESSION_SSH_AUTHENTICATED 0x10
469470
/* netconf subsystem requested */
470-
# define NC_SESSION_SSH_SUBSYS_NETCONF 0x08
471+
# define NC_SESSION_SSH_SUBSYS_NETCONF 0x20
471472
/* new SSH message arrived */
472-
# define NC_SESSION_SSH_NEW_MSG 0x10
473+
# define NC_SESSION_SSH_NEW_MSG 0x40
473474
/* this session is passed to nc_sshcb_msg() */
474-
# define NC_SESSION_SSH_MSG_CB 0x20
475+
# define NC_SESSION_SSH_MSG_CB 0x80
475476

476477
uint16_t ssh_auth_attempts; /**< number of failed SSH authentication attempts */
477478
#endif

src/session_server.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,12 +3389,12 @@ nc_server_ch_client_thread_session_cond_wait(struct nc_session *session, struct
33893389
/* CH LOCK */
33903390
pthread_mutex_lock(&session->opts.server.ch_lock);
33913391

3392-
session->flags |= NC_SESSION_CALLHOME;
3392+
session->flags |= NC_SESSION_CH_THREAD;
33933393

33943394
/* give the session to the user */
33953395
if (data->new_session_cb(data->client_name, session)) {
33963396
/* something is wrong, free the session */
3397-
session->flags &= ~NC_SESSION_CALLHOME;
3397+
session->flags &= ~NC_SESSION_CH_THREAD;
33983398

33993399
/* CH UNLOCK */
34003400
pthread_mutex_unlock(&session->opts.server.ch_lock);
@@ -3449,8 +3449,9 @@ nc_server_ch_client_thread_session_cond_wait(struct nc_session *session, struct
34493449

34503450
} while (session->status == NC_STATUS_RUNNING);
34513451

3452-
/* signal to nc_session_free() that CH registered this session not being valid anymore */
3453-
session->flags &= ~NC_SESSION_CALLHOME;
3452+
/* signal to nc_session_free() that CH thread is terminating */
3453+
session->flags &= ~NC_SESSION_CH_THREAD;
3454+
pthread_cond_signal(&session->opts.server.ch_cond);
34543455

34553456
/* CH UNLOCK */
34563457
pthread_mutex_unlock(&session->opts.server.ch_lock);

0 commit comments

Comments
 (0)