]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Rdns: Add timeout logic for TCP requests
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Jan 2022 10:00:17 +0000 (10:00 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Jan 2022 10:00:17 +0000 (10:00 +0000)
contrib/librdns/resolver.c
contrib/librdns/util.c

index a86dd403008329edddca9a35dda697cd65de6434..4193d6d28ac8adaf023f4afad6bc5090484eeeaf 100644 (file)
@@ -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);
index 9ced3ebd4828b18bdd23f4f117cf61e004551297..b7e1a2011ca857522816a45dcd2c22ea1ec1e0d0 100644 (file)
@@ -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