Skip to content

Commit 3bbb161

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 3bbb161

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/sbd-cluster.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
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
3842
#endif
3943

4044
#include "sbd.h"
@@ -58,6 +62,7 @@ static crm_cluster_t cluster;
5862
static gboolean sbd_remote_check(gpointer user_data);
5963
static long unsigned int find_pacemaker_remote(void);
6064
static void sbd_membership_destroy(gpointer user_data);
65+
static void cmap_destroy(void);
6166

6267

6368
#if SUPPORT_PLUGIN
@@ -168,10 +173,19 @@ static void sbd_cmap_notify_fn(
168173
}
169174

170175
static gboolean
171-
cmap_dispatch_callback (gpointer user_data)
176+
cmap_dispatch_callback (gint cmap_fd,
177+
GIOCondition condition,
178+
gpointer user_data)
172179
{
180+
/* CMAP connection lost */
181+
if (condition & G_IO_HUP) {
182+
cl_log(LOG_WARNING, "CMAP service connection lost\n");
183+
cmap_destroy();
184+
/* remove the source from the main loop */
185+
return G_SOURCE_REMOVE;
186+
}
173187
cmap_dispatch(cmap_handle, CS_DISPATCH_ALL);
174-
return TRUE;
188+
return G_SOURCE_CONTINUE;
175189
}
176190

177191
static void
@@ -222,7 +236,7 @@ sbd_get_two_node(void)
222236
cl_log(LOG_WARNING, "Couldn't create source for cmap\n");
223237
goto out;
224238
}
225-
g_source_set_callback(cmap_source, cmap_dispatch_callback, NULL, NULL);
239+
g_source_set_callback(cmap_source, G_SOURCE_FUNC(cmap_dispatch_callback), NULL, NULL);
226240
g_source_attach(cmap_source, NULL);
227241
}
228242

0 commit comments

Comments
 (0)