diff options
author | Oto Šťáva <oto.stava@nic.cz> | 2023-08-01 16:36:53 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2023-08-22 13:38:27 +0200 |
commit | 7aec8ebdf1428afcb7f5bc62764149ffeaf3d3fe (patch) | |
tree | 95183cf8c0654c6c4fafcd1299d4b661471d00f8 /daemon/io.c | |
parent | Merge !1444: manager: datamodel: fix /cache/ttl-max default (diff) | |
download | knot-resolver-7aec8ebdf1428afcb7f5bc62764149ffeaf3d3fe.tar.xz knot-resolver-7aec8ebdf1428afcb7f5bc62764149ffeaf3d3fe.zip |
daemon: more avoidance of excessive TCP reconnections
Previously this penalization was only triggered if the remote server
closed TCP. Now it's extended to us closing it when the server
(only) sends back some nonsense. At least for the cases which I could
see immediately.
That's just three trivial one-line additions; the rest is refactoring.
Adapted to 6.0 from commit 6468ab22 by Oto Šťáva <oto.stava@nic.cz>
Co-Authored-By: Vladimír Čunat <vladimir.cunat@nic.cz>
Diffstat (limited to 'daemon/io.c')
-rw-r--r-- | daemon/io.c | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/daemon/io.c b/daemon/io.c index 598d6ada..c077d91b 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -466,33 +466,6 @@ int io_listen_udp(uv_loop_t *loop, uv_udp_t *handle, int fd) } -static void tcp_disconnect(struct session2 *s, int errcode) -{ - if (kr_log_is_debug(IO, NULL)) { - struct sockaddr *peer = session2_get_peer(s); - char *peer_str = kr_straddr(peer); - kr_log_debug(IO, "=> connection to '%s' closed by peer (%s)\n", - peer_str ? peer_str : "", - uv_strerror(errcode)); - } - - if (!s->was_useful && s->outgoing) { - /* We want to penalize the IP address, if a task is asking a query. - * It might not be the right task, but that doesn't matter so much - * for attributing the useless session to the IP address. */ - struct qr_task *t = session2_tasklist_get_first(s); - struct kr_query *qry = NULL; - if (t) { - struct kr_request *req = worker_task_request(t); - qry = array_tail(req->rplan.pending); - } - if (qry) /* We reuse the error for connection, as it's quite similar. */ - qry->server_selection.error(qry, worker_task_get_transport(t), - KR_SELECTION_TCP_CONNECT_FAILED); - } - worker_end_tcp(s); -} - static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) { struct session2 *s = handle->data; @@ -510,7 +483,15 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf) } if (nread < 0 || !buf->base) { - tcp_disconnect(s, nread); + if (kr_log_is_debug(IO, NULL)) { + struct sockaddr *peer = session2_get_peer(s); + char *peer_str = kr_straddr(peer); + kr_log_debug(IO, "=> connection to '%s' closed by peer (%s)\n", + peer_str ? peer_str : "", + uv_strerror(nread)); + } + session2_penalize(s); + worker_end_tcp(s); return; } |