From bfe44a9785aa6334095b301837b09d7c48df8ab9 Mon Sep 17 00:00:00 2001 From: Erik Boasson Date: Wed, 27 Mar 2019 09:25:09 +0100 Subject: [PATCH] avoid debmon thread shutdown logging write errors During shutdown, the optional "debmon" thread for getting some information about internal state of the DDSI stack had a tendency to run into errors from calling write on a connection that had already been closed immediately after connecting successfully to wake the thread. Instead of blindly writing into the connection, it now checks whether it is supposed to shutdown before doing anything, avoiding this particular problem. Signed-off-by: Erik Boasson --- src/core/ddsi/src/q_debmon.c | 49 +++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/core/ddsi/src/q_debmon.c b/src/core/ddsi/src/q_debmon.c index eb83d81..beaa9bf 100644 --- a/src/core/ddsi/src/q_debmon.c +++ b/src/core/ddsi/src/q_debmon.c @@ -300,37 +300,46 @@ static int print_proxy_participants (struct thread_state1 *self, ddsi_tran_conn_ return x; } +static void debmon_handle_connection (struct debug_monitor *dm, ddsi_tran_conn_t conn) +{ + struct plugin *p; + int r = 0; + r += print_participants (dm->servts, conn); + if (r == 0) + r += print_proxy_participants (dm->servts, conn); + + /* Note: can only add plugins (at the tail) */ + ddsrt_mutex_lock (&dm->lock); + p = dm->plugins; + while (r == 0 && p != NULL) + { + ddsrt_mutex_unlock (&dm->lock); + r += p->fn (conn, cpf, p->arg); + ddsrt_mutex_lock (&dm->lock); + p = p->next; + } + ddsrt_mutex_unlock (&dm->lock); +} + static uint32_t debmon_main (void *vdm) { struct debug_monitor *dm = vdm; ddsrt_mutex_lock (&dm->lock); while (!dm->stop) { - ddsi_tran_conn_t conn; ddsrt_mutex_unlock (&dm->lock); - if ((conn = ddsi_listener_accept (dm->servsock)) != NULL) + ddsi_tran_conn_t conn = ddsi_listener_accept (dm->servsock); + ddsrt_mutex_lock (&dm->lock); + if (conn != NULL && !dm->stop) { - struct plugin *p; - int r = 0; - r += print_participants (dm->servts, conn); - if (r == 0) - r += print_proxy_participants (dm->servts, conn); - - /* Note: can only add plugins (at the tail) */ - ddsrt_mutex_lock (&dm->lock); - p = dm->plugins; - while (r == 0 && p != NULL) - { - ddsrt_mutex_unlock (&dm->lock); - r += p->fn (conn, cpf, p->arg); - ddsrt_mutex_lock (&dm->lock); - p = p->next; - } ddsrt_mutex_unlock (&dm->lock); - + debmon_handle_connection (dm, conn); + ddsrt_mutex_lock (&dm->lock); + } + if (conn != NULL) + { ddsi_conn_free (conn); } - ddsrt_mutex_lock (&dm->lock); } ddsrt_mutex_unlock (&dm->lock); return 0;