Skip to content

Commit

Permalink
Shutdown all connection threads when applications is terminated
Browse files Browse the repository at this point in the history
The conection threads are using the resources that are deallocated
in the main diod thread. If they are not shut down cleanly before
this deallocation we could get craches at shutdown due to this.
  • Loading branch information
Björn Ardö committed Mar 21, 2024
1 parent b1cebbe commit 893789f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions diod/diod.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ _service_run (srvmode_t mode, int rfdno, int wfdno)
errn_exit (n, "pthread_join _service_loop_rdma");
#endif

np_srv_shutdown(ss.srv);
diod_fini (ss.srv);
np_srv_destroy (ss.srv);
}
Expand Down
1 change: 1 addition & 0 deletions libnpfs/npfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ struct Npuser {
/* srv.c */
Npsrv *np_srv_create(int nwthread, int flags);
void np_srv_destroy(Npsrv *srv);
void np_srv_shutdown(Npsrv *srv);
void np_srv_remove_conn_pre(Npsrv *, Npconn *);
void np_srv_remove_conn_post(Npsrv *);
int np_srv_add_conn(Npsrv *, Npconn *);
Expand Down
17 changes: 17 additions & 0 deletions libnpfs/srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ np_srv_create(int nwthread, int flags)
return NULL;
}

/* Shut down all connection */
void
np_srv_shutdown(Npsrv *srv)
{
Npconn *cc;

/* Shut down all connections */
xpthread_mutex_lock(&srv->lock);
for (cc = srv->conns; cc != NULL; cc = cc->next)
pthread_cancel(cc->rthread);

/* Wait for all connections to shutdown... */
while (srv->conncount > 0)
xpthread_cond_wait(&srv->conncountcond, &srv->lock);
xpthread_mutex_unlock(&srv->lock);
}

void
np_srv_destroy(Npsrv *srv)
{
Expand Down

0 comments on commit 893789f

Please sign in to comment.