]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/udp_queue: rate-limit also other errors sendmmsg-logs-limit
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 5 Feb 2021 15:42:34 +0000 (16:42 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 5 Feb 2021 15:43:39 +0000 (16:43 +0100)
than EWOULDBLOCK, as long as the error remains the same.
Apparently we may print lots of these on Turris OS:
https://forum.turris.cz/t/5-1-8-kresd-throwing-many-errors-in-var-log-messages/14775

daemon/udp_queue.c

index 9cf39401a39c8b4f4816090c9c4edf4e20920b15..33c4cc3d58a21adb8833044939adb3c683133407 100644 (file)
@@ -75,18 +75,23 @@ static void udp_queue_send(int fd)
        if (!q->len) return;
        int sent_len = sendmmsg(fd, q->msgvec, q->len, 0);
        /* ATM we don't really do anything about failures. */
-       int err = sent_len < 0 ? errno : EAGAIN /* unknown error, really */;
+       const int err = sent_len < 0 ? errno : EAGAIN /* unknown error, really */;
        if (unlikely(sent_len != q->len)) {
-               if (err != EWOULDBLOCK) {
-                       kr_log_error("ERROR: udp sendmmsg() sent %d / %d; %s\n",
-                                       sent_len, q->len, strerror(err));
-               } else {
-                       const uint64_t stamp_now = kr_now();
-                       static uint64_t stamp_last = 0;
-                       if (stamp_now > stamp_last + 60*1000) {
+               /* Rate-limit the logs to at most once per minute,
+                * in case the error code remains the same. */
+               const uint64_t stamp_now = kr_now();
+               static uint64_t stamp_last = 0;
+               static int err_last = 0;
+               if (err != err_last || stamp_now > stamp_last + 60*1000) {
+                       if (err != EWOULDBLOCK) {
+                               kr_log_error("ERROR: udp sendmmsg() sent %d / %d; %s"
+                                               "(reported at most once per minute)\n",
+                                               sent_len, q->len, strerror(err));
+                       } else {
                                kr_log_info("WARNING: dropped UDP reply packet(s) due to network overload (reported at most once per minute)\n");
-                               stamp_last = stamp_now;
                        }
+                       stamp_last = stamp_now;
+                       err_last = err;
                }
        }
        for (int i = 0; i < q->len; ++i) {