]> source.dussan.org Git - rspamd.git/commitdiff
Fix timeouts in map watch.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Oct 2013 21:32:18 +0000 (22:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 26 Oct 2013 21:32:18 +0000 (22:32 +0100)
src/map.c
src/util.h

index ea7f0adbb91fcd05ffa207fdfffff8da804e146f..7c61dcc9eb1e268e618e90fd98b300e276c29317 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -767,12 +767,12 @@ file_callback (gint fd, short what, void *ud)
        struct rspamd_map              *map = ud;
        struct file_map_data           *data = map->map_data;
        struct stat                     st;
-       gdouble                                                 jittered_msec;
+       gdouble                                                 jittered_sec;
 
        /* Plan event again with jitter */
        evtimer_del (&map->ev);
-       jittered_msec = (map->cfg->map_timeout + g_random_double ());
-       msec_to_tv (jittered_msec, &map->tv);
+       jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout);
+       double_to_tv (jittered_sec, &map->tv);
 
        evtimer_add (&map->ev, &map->tv);
 
@@ -900,12 +900,12 @@ http_callback (gint fd, short what, void *ud)
        struct http_map_data           *data = map->map_data;
        gint                            sock;
        struct http_callback_data      *cbd;
-       gdouble                                                 jittered_msec;
+       gdouble                                                 jittered_sec;
 
        /* Plan event again with jitter */
        evtimer_del (&map->ev);
-       jittered_msec = (map->cfg->map_timeout + g_random_double ());
-       msec_to_tv (jittered_msec, &map->tv);
+       jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout);
+       double_to_tv (jittered_sec, &map->tv);
        evtimer_add (&map->ev, &map->tv);
 
        if (g_atomic_int_get (map->locked)) {
@@ -944,7 +944,7 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base)
        GList                          *cur = cfg->maps;
        struct rspamd_map              *map;
        struct file_map_data           *fdata;
-       gdouble                                                 jittered_msec;
+       gdouble                                                 jittered_sec;
 
        /* First of all do synced read of data */
        while (cur) {
@@ -960,8 +960,8 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base)
                                read_map_file (map, map->map_data);
                        }
                        /* Plan event with jitter */
-                       jittered_msec = (map->cfg->map_timeout + g_random_double ()) / 2.;
-                       msec_to_tv (jittered_msec, &map->tv);
+                       jittered_sec = (map->cfg->map_timeout + g_random_double ()  * map->cfg->map_timeout) / 2.;
+                       double_to_tv (jittered_sec, &map->tv);
                        evtimer_add (&map->ev, &map->tv);
                }
                else if (map->protocol == MAP_PROTO_HTTP) {
@@ -970,8 +970,8 @@ start_map_watch (struct config_file *cfg, struct event_base *ev_base)
                        /* Read initial data */
                        read_http_sync (map, map->map_data);
                        /* Plan event with jitter */
-                       jittered_msec = (map->cfg->map_timeout + g_random_double ());
-                       msec_to_tv (jittered_msec, &map->tv);
+                       jittered_sec = (map->cfg->map_timeout + g_random_double () * map->cfg->map_timeout);
+                       double_to_tv (jittered_sec, &map->tv);
                        evtimer_add (&map->ev, &map->tv);
                }
                cur = g_list_next (cur);
index 405d289a3384296956741ba3daec1585e0b7b235..2526a981a49ff73f1e12298a2860258f02a83648 100644 (file)
@@ -216,6 +216,7 @@ gchar * escape_braces_addr_fstr (memory_pool_t *pool, f_str_t *in);
  * Convert milliseconds to timeval fields
  */
 #define msec_to_tv(msec, tv) do { (tv)->tv_sec = (msec) / 1000; (tv)->tv_usec = ((msec) - (tv)->tv_sec * 1000) * 1000; } while(0)
+#define double_to_tv(dbl, tv) do { (tv)->tv_sec = (int)(dbl); (tv)->tv_usec = ((dbl) - (int)(dbl))*1000*1000; } while(0)
 #define tv_to_msec(tv) (tv)->tv_sec * 1000 + (tv)->tv_usec / 1000
 
 /* Compare two emails for building emails tree */