[PATCH] Cache messaging dgm connections
Jeremy Allison
jra at samba.org
Sat Sep 17 05:53:29 UTC 2016
On Fri, Sep 16, 2016 at 10:06:56PM -0700, Jeremy Allison wrote:
> 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.
Slightly better canary code that catches ev addition and
destruction.
-------------- next part --------------
>From d021fe0366a487fa5864893cd640f9ef06876f68 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;
}
--
1.9.1
>From 90fffb29e883c02bfee634e5e379db1fcccea2d4 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;
}
--
1.9.1
>From 04728d3da417d0a4b844413e9023e7fbc2012e92 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;
}
--
1.9.1
>From f8b556e783e09915ff0ba72ccac3022fcd0dbc11 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 | 29 +++++++++++++++++++++++++++++
lib/poll_funcs/poll_funcs_tevent.h | 1 +
source3/lib/messages.c | 10 ++++++++++
source4/lib/messaging/messaging.c | 8 ++++++++
4 files changed, 48 insertions(+)
diff --git a/lib/poll_funcs/poll_funcs_tevent.c b/lib/poll_funcs/poll_funcs_tevent.c
index 233e911..b36402d 100644
--- a/lib/poll_funcs/poll_funcs_tevent.c
+++ b/lib/poll_funcs/poll_funcs_tevent.c
@@ -84,6 +84,22 @@ struct poll_funcs_tevent_handle {
struct poll_funcs_tevent_context *ctx;
};
+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));
+ (*debug_fn_ptr)(dbg_str);
+ talloc_free(dbg_str);
+ return 0;
+}
static uint16_t poll_events_to_tevent(short events)
{
uint16_t ret = 0;
@@ -538,6 +554,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 +605,18 @@ 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);
+
+ {
+ char *dbg_str = talloc_asprintf(NULL,
+ "CANARY ADDING EV_CTX %p\n",
+ ev);
+ (*debug_fn_ptr)(dbg_str);
+ talloc_free(dbg_str);
+ }
+
return ctx;
fail:
TALLOC_FREE(ctx);
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/source3/lib/messages.c b/source3/lib/messages.c
index 3ed6dfe..1ca0f01 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -56,6 +56,7 @@
#include "lib/util/server_id_db.h"
#include "lib/messages_dgm_ref.h"
#include "lib/messages_util.h"
+#include "lib/poll_funcs/poll_funcs_tevent.h"
struct messaging_callback {
struct messaging_callback *prev, *next;
@@ -183,6 +184,11 @@ static const char *private_path(const char *name)
return talloc_asprintf(talloc_tos(), "%s/%s", lp_private_dir(), name);
}
+static void canary_debug(const char *str)
+{
+ DEBUG(0,("%s", str));
+}
+
struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev)
{
@@ -234,6 +240,8 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
return NULL;
}
+ poll_funcs_tevent_set_debug_fn(canary_debug);
+
ctx->msg_dgm_ref = messaging_dgm_ref(
ctx, ctx->event_ctx, &ctx->id.unique_id,
priv_path, lck_path, messaging_recv_cb, ctx, &ret);
@@ -307,6 +315,8 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
return NT_STATUS_NO_MEMORY;
}
+ poll_funcs_tevent_set_debug_fn(canary_debug);
+
msg_ctx->msg_dgm_ref = messaging_dgm_ref(
msg_ctx, msg_ctx->event_ctx, &msg_ctx->id.unique_id,
private_path("msg.sock"), lck_path,
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index d0beef6..62b0198 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
*/
@@ -374,6 +380,8 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
goto fail;
}
+ poll_funcs_tevent_set_debug_fn(canary_debug);
+
msg->msg_dgm_ref = messaging_dgm_ref(
msg, ev, &server_id.unique_id, msg->sock_dir, msg->lock_dir,
imessaging_dgm_recv, msg, &ret);
--
1.9.1
More information about the samba-technical
mailing list