From 023e09156f3098c2c6a1e7d6c5568081c8be12a6 Mon Sep 17 00:00:00 2001 From: Itamar Tal Date: Mon, 16 Mar 2020 13:37:47 +0200 Subject: [PATCH 1/2] added lock debug --- src/utils/glock.c | 4 ++-- src/utils/glock.h | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/utils/glock.c b/src/utils/glock.c index 7fe0c6dc3..7a4e786a2 100644 --- a/src/utils/glock.c +++ b/src/utils/glock.c @@ -36,13 +36,13 @@ static void nn_glock_init (void) InitializeCriticalSection (&nn_glock_cs); } -void nn_glock_lock (void) +void _nn_glock_lock (void) { nn_glock_init (); EnterCriticalSection (&nn_glock_cs); } -void nn_glock_unlock (void) +void _nn_glock_unlock (void) { nn_glock_init (); LeaveCriticalSection (&nn_glock_cs); diff --git a/src/utils/glock.h b/src/utils/glock.h index d264d89f5..1f8deee52 100644 --- a/src/utils/glock.h +++ b/src/utils/glock.h @@ -26,8 +26,27 @@ /* Implementation of a global lock (critical section). The lock is meant to be used to synchronise the initialisation/termination of the library. */ -void nn_glock_lock (void); -void nn_glock_unlock (void); + +#define nn_glock_lock() do { \ + FILE *fp = fopen("nanomsg-lock.log", "a"); \ + fprintf(fp, "%s:%d[%s]: nn_glock_lock() IN\n", __FILE__, __LINE__, __FUNCTION__); \ + _nn_glock_lock(); \ + fprintf(fp, "%s:%d[%s]: nn_glock_lock() OUT\n", __FILE__, __LINE__, __FUNCTION__); \ + fclose(fp); \ + } while (0) + + +#define nn_glock_unlock() do { \ + FILE *fp = fopen("nanomsg-lock.log", "a"); \ + fprintf(fp, "%s:%d[%s]: nn_glock_unlock() IN\n", __FILE__, __LINE__, __FUNCTION__); \ + _nn_glock_unlock(); \ + fprintf(fp, "%s:%d[%s]: nn_glock_unlock() OUT\n", __FILE__, __LINE__, __FUNCTION__); \ + fclose(fp); \ + } while (0) + + +void _nn_glock_lock (void); +void _nn_glock_unlock (void); #endif From 8cb663a1a05d8375fb8d2a5455b62055ceb4e3d9 Mon Sep 17 00:00:00 2001 From: Itamar Tal Date: Wed, 18 Mar 2020 16:38:01 +0200 Subject: [PATCH 2/2] fix yet another deadlock in nanomsg-xp --- src/aio/usock_win.inc | 2 +- src/core/global.c | 55 ------------------------------------------- src/utils/glock.h | 29 +++++++++++++++-------- 3 files changed, 20 insertions(+), 66 deletions(-) diff --git a/src/aio/usock_win.inc b/src/aio/usock_win.inc index 42ba60e61..5005eb632 100644 --- a/src/aio/usock_win.inc +++ b/src/aio/usock_win.inc @@ -293,7 +293,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener) /* Wait for the incoming connection. */ memset (&listener->in.olpd, 0, sizeof (listener->in.olpd)); brc = AcceptEx (listener->s, self->s, listener->ainfo, 0, 256, 256, &nbytes, - &listener->in.olpd); + &listener->in.olpd); /* Immediate success. */ if (nn_fast (brc == TRUE)) { diff --git a/src/core/global.c b/src/core/global.c index f918e9736..5581ed323 100644 --- a/src/core/global.c +++ b/src/core/global.c @@ -1112,60 +1112,6 @@ static void nn_global_submit_errors (int i, struct nn_sock *s, } } -static void nn_global_submit_statistics () -{ - int i; - struct nn_sock *s; - - /* TODO(tailhook) optimized it to use nsocks and unused */ - for(i = 0; i < NN_MAX_SOCKETS; ++i) { - - nn_glock_lock (); - s = self.socks [i]; - if (!s) { - nn_glock_unlock (); - continue; - } - if (i == self.statistics_socket) { - nn_glock_unlock (); - continue; - } - nn_ctx_enter (&s->ctx); - nn_glock_unlock (); - - nn_global_submit_counter (i, s, - "established_connections", s->statistics.established_connections); - nn_global_submit_counter (i, s, - "accepted_connections", s->statistics.accepted_connections); - nn_global_submit_counter (i, s, - "dropped_connections", s->statistics.dropped_connections); - nn_global_submit_counter (i, s, - "broken_connections", s->statistics.broken_connections); - nn_global_submit_counter (i, s, - "connect_errors", s->statistics.connect_errors); - nn_global_submit_counter (i, s, - "bind_errors", s->statistics.bind_errors); - nn_global_submit_counter (i, s, - "accept_errors", s->statistics.accept_errors); - nn_global_submit_counter (i, s, - "messages_sent", s->statistics.messages_sent); - nn_global_submit_counter (i, s, - "messages_received", s->statistics.messages_received); - nn_global_submit_counter (i, s, - "bytes_sent", s->statistics.bytes_sent); - nn_global_submit_counter (i, s, - "bytes_received", s->statistics.bytes_received); - nn_global_submit_level (i, s, - "current_connections", s->statistics.current_connections); - nn_global_submit_level (i, s, - "inprogress_connections", s->statistics.inprogress_connections); - nn_global_submit_level (i, s, - "current_snd_priority", s->statistics.current_snd_priority); - nn_global_submit_errors (i, s, - "current_ep_errors", s->statistics.current_ep_errors); - nn_ctx_leave (&s->ctx); - } -} static int nn_global_create_ep (int s, const char *addr, int bind) { @@ -1285,7 +1231,6 @@ static void nn_global_handler (struct nn_fsm *self, case NN_GLOBAL_SRC_STAT_TIMER: switch (type) { case NN_TIMER_TIMEOUT: - nn_global_submit_statistics (); /* No need to change state */ nn_timer_stop (&global->stat_timer); return; diff --git a/src/utils/glock.h b/src/utils/glock.h index 1f8deee52..4ac1836c7 100644 --- a/src/utils/glock.h +++ b/src/utils/glock.h @@ -27,23 +27,32 @@ be used to synchronise the initialisation/termination of the library. */ -#define nn_glock_lock() do { \ - FILE *fp = fopen("nanomsg-lock.log", "a"); \ - fprintf(fp, "%s:%d[%s]: nn_glock_lock() IN\n", __FILE__, __LINE__, __FUNCTION__); \ +#ifdef GLOBCAL_LOCK_DBG +#define nn_glock_lock() do { \ + DWORD pid = GetCurrentProcessId(); \ + FILE *fp = fopen("nanomsg-lock.log", "a"); \ + fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_lock() IN\n", pid, __FILE__, __LINE__, __FUNCTION__); \ _nn_glock_lock(); \ - fprintf(fp, "%s:%d[%s]: nn_glock_lock() OUT\n", __FILE__, __LINE__, __FUNCTION__); \ + fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_lock() OUT\n", pid, __FILE__, __LINE__, __FUNCTION__); \ fclose(fp); \ } while (0) -#define nn_glock_unlock() do { \ - FILE *fp = fopen("nanomsg-lock.log", "a"); \ - fprintf(fp, "%s:%d[%s]: nn_glock_unlock() IN\n", __FILE__, __LINE__, __FUNCTION__); \ - _nn_glock_unlock(); \ - fprintf(fp, "%s:%d[%s]: nn_glock_unlock() OUT\n", __FILE__, __LINE__, __FUNCTION__); \ - fclose(fp); \ +#define nn_glock_unlock() do { \ + FILE *fp = fopen("nanomsg-lock.log", "a"); \ + DWORD pid = GetCurrentProcessId(); \ + fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_unlock() IN\n", pid, __FILE__, __LINE__, __FUNCTION__); \ + _nn_glock_unlock(); \ + fprintf(fp, "pid=%d:%s:%d[%s]: nn_glock_unlock() OUT\n", pid, __FILE__, __LINE__, __FUNCTION__); \ + fclose(fp); \ } while (0) +#else + +#define nn_glock_lock() _nn_glock_lock() +#define nn_glock_unlock() _nn_glock_unlock() + +#endif void _nn_glock_lock (void); void _nn_glock_unlock (void);