From: Vsevolod Stakhov Date: Thu, 30 Jun 2016 12:49:46 +0000 (+0100) Subject: [Fix] Fix maps locking X-Git-Tag: 1.3.0~210 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=67667856ab59e89e573980eb2002e02db742d50b;p=rspamd.git [Fix] Fix maps locking --- diff --git a/src/libutil/map.c b/src/libutil/map.c index 0a73d4c72..eafb85f11 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -599,7 +599,11 @@ rspamd_map_periodic_dtor (struct map_periodic_cbdata *periodic) } rspamd_map_schedule_periodic (periodic->map, FALSE, FALSE, FALSE); - g_atomic_int_set (periodic->map->locked, 0); + + if (periodic->locked) { + g_atomic_int_set (periodic->map->locked, 0); + } + g_slice_free1 (sizeof (*periodic), periodic); } @@ -895,11 +899,32 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud) { struct rspamd_map_backend *bk; struct map_periodic_cbdata *cbd = ud; + struct rspamd_map *map; + + map = cbd->map; + + if (!cbd->locked) { + if (!g_atomic_int_compare_and_exchange (cbd->map->locked, 0, 1)) { + msg_debug_map ( + "don't try to reread map as it is locked by other process, " + "will reread it later"); + rspamd_map_schedule_periodic (map, TRUE, FALSE, FALSE); + MAP_RELEASE (cbd, "periodic"); + + return; + } + else { + cbd->locked = TRUE; + } + } if (cbd->errored) { /* We should not check other backends if some backend has failed */ rspamd_map_schedule_periodic (cbd->map, FALSE, FALSE, TRUE); - g_atomic_int_set (cbd->map->locked, 0); + + if (cbd->locked) { + g_atomic_int_set (cbd->map->locked, 0); + } MAP_RELEASE (cbd, "periodic"); return; @@ -951,15 +976,7 @@ rspamd_map_watch (struct rspamd_config *cfg, map->ev_base = ev_base; map->r = resolver; - if (!g_atomic_int_compare_and_exchange (map->locked, 0, 1)) { - msg_debug_map ( - "don't try to reread map as it is locked by other process, " - "will reread it later"); - rspamd_map_schedule_periodic (map, TRUE, TRUE, FALSE); - } - else { - rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE); - } + rspamd_map_schedule_periodic (map, FALSE, TRUE, FALSE); cur = g_list_next (cur); } diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h index ca4174821..194aef2ef 100644 --- a/src/libutil/map_private.h +++ b/src/libutil/map_private.h @@ -123,6 +123,7 @@ struct map_periodic_cbdata { gboolean need_modify; gboolean errored; guint cur_backend; + gboolean locked; ref_entry_t ref; };