[PATCH] Cache messaging dgm connections

Jeremy Allison jra at samba.org
Sat Sep 17 05:06:56 UTC 2016


On Fri, Sep 16, 2016 at 02:03:42PM -0700, Jeremy Allison wrote:
> On Fri, Sep 16, 2016 at 09:05:23AM -0700, Jeremy Allison wrote:
> > On Fri, Sep 16, 2016 at 06:00:44PM +0200, Ralph Böhme wrote:
> > > On Fri, Sep 16, 2016 at 08:36:33AM -0700, Jeremy Allison wrote:
> > > > On Fri, Sep 16, 2016 at 11:29:06AM +0200, Ralph Böhme wrote:
> > > > > On Thu, Sep 15, 2016 at 10:09:18AM -0700, Jeremy Allison wrote:
> > > > > > On Thu, Sep 15, 2016 at 06:38:25PM +0200, Ralph Böhme wrote:
> > > > > > > 
> > > > > > > I got one through with these two patches. Running more...
> > > > > > > 
> > > > > > > Cheerio!
> > > > > > 
> > > > > > Oh, this looks more elegant than the reparent struct poll_funcs_tevent_context
> > > > > > to ev patch I just posted...
> > > > > > 
> > > > > > The:
> > > > > > 
> > > > > >  +     TALLOC_FREE(msg->msg_dgm_ref);
> > > > > > 
> > > > > > looks very clever :-).
> > > > > 
> > > > > it passed three more autobuilds. Shall we push it?
> > > > 
> > > > Yes please - the version we discussed on the phone
> > > > with the free of the timer events followed by context,
> > > > plus the TALLOC_FREE(msg->msg_dgm_ref); change !
> > > 
> > > Then the attached is the one. Please push if ok.
> > 
> > 
> > It's missing the:
> > 
> > +     size_t num_contexts = talloc_array_length(state->contexts);
> > 
> > in the second patch. With that added, pushed !
> 
> Still got the crash with this in autobuild, now with the backtrace
> below. So we're still not catching everything (or something else
> is freeing ev behind our backs :-).
> 
> As I know we're going to be co-located on Monday, let's
> schedule a time to look at this directly at the SNIA
> conf.

In the meantime, here's what I'm running a private autobuild
with in the hope of catching the place where ev gets deleted.
-------------- next part --------------
>From 020955e53325d2fefaa19db6f7c4f0844f240ead Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Thu, 15 Sep 2016 14:19:27 +0200
Subject: [PATCH 1/4] lib/poll_funcs: free timers in
 poll_funcs_state_destructor()

Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 lib/poll_funcs/poll_funcs_tevent.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c
index 3059ebc..3d79b75 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -474,6 +474,7 @@ struct poll_funcs *poll_funcs_init_tevent(TALLOC_CTX *mem_ctx)
 static int poll_funcs_state_destructor(struct poll_funcs_state *state)
 {
 	size_t num_watches = talloc_array_length(state->watches);
+	size_t num_timeouts = talloc_array_length(state->timeouts);
 	size_t i;
 	/*
 	 * Make sure the watches are cleared before the contexts. The watches
@@ -482,6 +483,9 @@ static int poll_funcs_state_destructor(struct poll_funcs_state *state)
 	for (i=0; i<num_watches; i++) {
 		TALLOC_FREE(state->watches[i]);
 	}
+	for (i=0; i<num_timeouts; i++) {
+		TALLOC_FREE(state->timeouts[i]);
+	}
 	return 0;
 }
 
-- 
2.7.4


>From 704e6fed8843bdb9a29a1b7f73558d8500048dc3 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Fri, 16 Sep 2016 17:55:56 +0200
Subject: [PATCH 2/4] lib/poll_funcs: free contexts in
 poll_funcs_state_destructor()

This ensures the destructors get called in the proper order.

Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 lib/poll_funcs/poll_funcs_tevent.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c
index 3d79b75..233e911 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -475,6 +475,7 @@ static int poll_funcs_state_destructor(struct poll_funcs_state *state)
 {
 	size_t num_watches = talloc_array_length(state->watches);
 	size_t num_timeouts = talloc_array_length(state->timeouts);
+	size_t num_contexts = talloc_array_length(state->contexts);
 	size_t i;
 	/*
 	 * Make sure the watches are cleared before the contexts. The watches
@@ -486,6 +487,9 @@ static int poll_funcs_state_destructor(struct poll_funcs_state *state)
 	for (i=0; i<num_timeouts; i++) {
 		TALLOC_FREE(state->timeouts[i]);
 	}
+	for (i=0; i<num_contexts; i++) {
+		TALLOC_FREE(state->contexts[i]);
+	}
 	return 0;
 }
 
-- 
2.7.4


>From e7e0727a3f0faf9d4f1dd2ad041af330fe544702 Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Thu, 15 Sep 2016 14:19:51 +0200
Subject: [PATCH 3/4] s4/messaging: let the imessaging ctx destructor free
 msg_dgm_ref

Signed-off-by: Ralph Boehme <slow at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
---
 source4/lib/messaging/messaging.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index ea50627..d0beef6 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -304,6 +304,7 @@ static struct imessaging_context *msg_ctxs;
 static int imessaging_context_destructor(struct imessaging_context *msg)
 {
 	DLIST_REMOVE(msg_ctxs, msg);
+	TALLOC_FREE(msg->msg_dgm_ref);
 	return 0;
 }
 
-- 
2.7.4


>From 1874d04aded66a81807d940732a4322115770187 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 16 Sep 2016 22:02:03 -0700
Subject: [PATCH 4/4] WIP. Add canary destructor to track ev_ctx free.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 lib/poll_funcs/poll_funcs_tevent.c | 26 ++++++++++++++++++++++++++
 lib/poll_funcs/poll_funcs_tevent.h |  1 +
 source4/lib/messaging/messaging.c  |  8 ++++++++
 3 files changed, 35 insertions(+)

diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c
index 233e911..605662d 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -530,6 +530,8 @@ static bool poll_funcs_context_slot_find(struct poll_funcs_state *state,
 static int poll_funcs_tevent_context_destructor(
 	struct poll_funcs_tevent_context *ctx);
 
+static int canary_destructor(char *str);
+
 static struct poll_funcs_tevent_context *poll_funcs_tevent_context_new(
 	TALLOC_CTX *mem_ctx, struct poll_funcs_state *state,
 	struct tevent_context *ev, unsigned slot)
@@ -538,6 +540,7 @@ static struct poll_funcs_tevent_context *poll_funcs_tevent_context_new(
 	size_t num_watches = talloc_array_length(state->watches);
 	size_t num_timeouts = talloc_array_length(state->timeouts);
 	size_t i;
+	char *canary = NULL;
 
 	ctx = talloc(mem_ctx, struct poll_funcs_tevent_context);
 	if (ctx == NULL) {
@@ -588,6 +591,10 @@ static struct poll_funcs_tevent_context *poll_funcs_tevent_context_new(
 	}
 
 	talloc_set_destructor(ctx, poll_funcs_tevent_context_destructor);
+
+	canary = talloc_memdup(ev, "canary", 7);
+	talloc_set_destructor(canary, canary_destructor);
+
 	return ctx;
 fail:
 	TALLOC_FREE(ctx);
@@ -671,3 +678,22 @@ static int poll_funcs_tevent_handle_destructor(
 	}
 	return 0;
 }
+
+static void (*debug_fn_ptr)(const char *str);
+
+void poll_funcs_tevent_set_debug_fn(void (*fn)(const char *str))
+{
+	debug_fn_ptr = fn;
+}
+
+static int canary_destructor(char *str)
+{
+	char *dbg_str = talloc_asprintf(NULL,
+				"CANARY DESTROYING EV_CTX %p\n",
+				talloc_parent(str));
+	if (debug_fn_ptr) {
+		(*debug_fn_ptr)(dbg_str);
+	}
+	talloc_free(dbg_str);
+	return 0;
+}
diff --git a/lib/poll_funcs/poll_funcs_tevent.h b/lib/poll_funcs/poll_funcs_tevent.h
index 8b2964c..0d2d293 100644
--- a/lib/poll_funcs/poll_funcs_tevent.h
+++ b/lib/poll_funcs/poll_funcs_tevent.h
@@ -35,4 +35,5 @@ struct poll_funcs *poll_funcs_init_tevent(TALLOC_CTX *mem_ctx);
 void *poll_funcs_tevent_register(TALLOC_CTX *mem_ctx, struct poll_funcs *f,
 				 struct tevent_context *ev);
 
+void poll_funcs_tevent_set_debug_fn(void (*fn)(const char *str));
 #endif
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index d0beef6..5f7a78f 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -38,6 +38,7 @@
 #include "../source3/lib/messages_dgm_ref.h"
 #include "../source3/lib/messages_util.h"
 #include <tdb.h>
+#include "lib/poll_funcs/poll_funcs_tevent.h"
 
 /* change the message version with any incompatible changes in the protocol */
 #define IMESSAGING_VERSION 1
@@ -324,6 +325,11 @@ void imessaging_dgm_unref_all(void)
 	}
 }
 
+static void canary_debug(const char *str)
+{
+	DEBUG(0,("%s", str));
+}
+
 /*
   create the listening socket and setup the dispatcher
 */
@@ -382,6 +388,8 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
+	poll_funcs_tevent_set_debug_fn(canary_debug);
+
 	msg->server_id     = server_id;
 	msg->idr           = idr_init(msg);
 	if (msg->idr == NULL) {
-- 
2.7.4



More information about the samba-technical mailing list