From 893789f678de1661a47dc5d5e8be950f1c4ca07b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ard=C3=B6?= Date: Mon, 18 Mar 2024 16:11:23 +0100 Subject: [PATCH] Shutdown all connection threads when applications is terminated 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. --- diod/diod.c | 1 + libnpfs/npfs.h | 1 + libnpfs/srv.c | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/diod/diod.c b/diod/diod.c index c7218701..ceb49f1a 100644 --- a/diod/diod.c +++ b/diod/diod.c @@ -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); } diff --git a/libnpfs/npfs.h b/libnpfs/npfs.h index 88859991..8a399866 100644 --- a/libnpfs/npfs.h +++ b/libnpfs/npfs.h @@ -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 *); diff --git a/libnpfs/srv.c b/libnpfs/srv.c index 0bd12b45..41ee2f97 100644 --- a/libnpfs/srv.c +++ b/libnpfs/srv.c @@ -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) {