Skip to content

Commit 838dd14

Browse files
committed
Fix: sbd-cluster: stop dispatching cmap if disconnected
If cmap socket is in HUP state, attempt to dispatch incoming events will trigger the callback again and cause infinite loop with high CPU load. Added check should solve this by destroying the cmap connection and removing it from the main loop.
1 parent e9be8d9 commit 838dd14

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/sbd-cluster.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535

3636
#if CHECK_TWO_NODE
3737
#include <glib-unix.h>
38+
// available since glib 2.58
39+
#ifndef G_SOURCE_FUNC
40+
#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f))
41+
#endif
42+
// available since glib 2.32
43+
#ifndef G_SOURCE_REMOVE
44+
#define G_SOURCE_REMOVE FALSE
45+
#endif
46+
// available since glib 2.32
47+
#ifndef G_SOURCE_CONTINUE
48+
#define G_SOURCE_CONTINUE TRUE
49+
#endif
3850
#endif
3951

4052
#include "sbd.h"
@@ -58,6 +70,9 @@ static crm_cluster_t cluster;
5870
static gboolean sbd_remote_check(gpointer user_data);
5971
static long unsigned int find_pacemaker_remote(void);
6072
static void sbd_membership_destroy(gpointer user_data);
73+
#if CHECK_TWO_NODE
74+
static void cmap_destroy(void);
75+
#endif
6176

6277

6378
#if SUPPORT_PLUGIN
@@ -168,10 +183,19 @@ static void sbd_cmap_notify_fn(
168183
}
169184

170185
static gboolean
171-
cmap_dispatch_callback (gpointer user_data)
186+
cmap_dispatch_callback (gint cmap_fd,
187+
GIOCondition condition,
188+
gpointer user_data)
172189
{
190+
/* CMAP connection lost */
191+
if (condition & G_IO_HUP) {
192+
cl_log(LOG_WARNING, "CMAP service connection lost\n");
193+
cmap_destroy();
194+
/* remove the source from the main loop */
195+
return G_SOURCE_REMOVE;
196+
}
173197
cmap_dispatch(cmap_handle, CS_DISPATCH_ALL);
174-
return TRUE;
198+
return G_SOURCE_CONTINUE;
175199
}
176200

177201
static void
@@ -222,7 +246,7 @@ sbd_get_two_node(void)
222246
cl_log(LOG_WARNING, "Couldn't create source for cmap\n");
223247
goto out;
224248
}
225-
g_source_set_callback(cmap_source, cmap_dispatch_callback, NULL, NULL);
249+
g_source_set_callback(cmap_source, G_SOURCE_FUNC(cmap_dispatch_callback), NULL, NULL);
226250
g_source_attach(cmap_source, NULL);
227251
}
228252

0 commit comments

Comments
 (0)