commit 3b0e294: [Project] Rdns: Add timeout logic for TCP requests
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jan 5 11:28:20 UTC 2022
Author: Vsevolod Stakhov
Date: 2022-01-05 10:00:17 +0000
URL: https://github.com/rspamd/rspamd/commit/3b0e294c489334153de206452b4319558343e8d5
[Project] Rdns: Add timeout logic for TCP requests
---
contrib/librdns/resolver.c | 13 +++++++++++++
contrib/librdns/util.c | 6 ++++++
2 files changed, 19 insertions(+)
diff --git a/contrib/librdns/resolver.c b/contrib/librdns/resolver.c
index a86dd4030..4193d6d28 100644
--- a/contrib/librdns/resolver.c
+++ b/contrib/librdns/resolver.c
@@ -498,6 +498,9 @@ rdns_reschedule_req_over_tcp (struct rdns_request *req, struct rdns_server *serv
}
}
+ req->async_event = resolver->async->add_timer (resolver->async->data,
+ req->timeout, req);
+
kh_value(req->io->requests, k) = req;
REF_RETAIN(ioc);
REF_RELEASE(old_ioc);
@@ -618,6 +621,16 @@ rdns_process_timer (void *arg)
UPSTREAM_FAIL (req->io->srv, time (NULL));
}
+ if (req->state == RDNS_REQUEST_TCP) {
+ rep = rdns_make_reply (req, RDNS_RC_TIMEOUT);
+ rdns_request_unschedule (req);
+ req->state = RDNS_REQUEST_REPLIED;
+ req->func (rep, req->arg);
+ REF_RELEASE (req);
+
+ return;
+ }
+
if (req->retransmits == 0) {
rep = rdns_make_reply (req, RDNS_RC_TIMEOUT);
diff --git a/contrib/librdns/util.c b/contrib/librdns/util.c
index 9ced3ebd4..b7e1a2011 100644
--- a/contrib/librdns/util.c
+++ b/contrib/librdns/util.c
@@ -643,6 +643,12 @@ rdns_request_unschedule (struct rdns_request *req)
req->async_event = NULL;
}
}
+ else if (req->state == RDNS_REQUEST_TCP) {
+ req->async->del_timer(req->async->data,
+ req->async_event);
+
+ req->async_event = NULL;
+ }
}
void
More information about the Commits
mailing list