]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
graphite: use TCP timeout value derived from publish interval
authorPetr Špaček <petr.spacek@nic.cz>
Mon, 29 Jun 2020 13:58:10 +0000 (15:58 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 29 Jun 2020 14:01:09 +0000 (16:01 +0200)
It seems pointless to accumulate "late" connection attempts.

modules/graphite/graphite.lua

index 902913f8c133bf92088e5a25dab77bcd4509f5b5..e2ac67eb09e7917d5cd2817bb4e05921595312d2 100644 (file)
@@ -13,10 +13,18 @@ local proto_txt = {
 
 local function make_socket(host, port, stype)
        local s, err, status
+       -- timeout before next interval begins (roughly)
+       local timeout_sec = (M.interval - 10) / sec
 
        s = socket.connect({ host = host, port = port, type = stype })
        s:setmode('bn', 'bn')
-       status, err = pcall(s.connect, s)
+       s:settimeout(timeout_sec)
+       status, err = pcall(s.connect, s, timeout_sec)
+       if status == true and err == nil then
+               err = 'connect timeout'
+               s:close()
+               status = false
+       end
 
        if not status then
                log('[graphite] connecting: %s@%d %s reason: %s',