A DNS-over-TCP session counts its pipelined queries in ds->nb_queries, up
to DNS_STREAM_MAX_PIPELINED_REQ (4), and only dns_recv_nameserver()
releases a slot, when a response is delivered. But when a query expires
without response, dns_process_query_exp() only decrements onfly_queries.
After 4 unanswered queries, the session is thus neither in the free nor in
the idle list anymore: it is never reused nor released and its connection
remains open forever, while new queries open new connections. With a TCP
nameserver not answering some names, one connection is leaked every 4
such queries, without limit.
Let's release the slot when a query expires, and move the session to the
free or idle list, under the stream server's lock, exactly as done when a
response is received.
This was introduced in 2.4 with commit
fd647d5f5 ("MEDIUM: dns: adds code
to support pipelined DNS requests over TCP."), so this must be backported
to all stable branches.
static struct task *dns_process_query_exp(struct task *t, void *context, unsigned int state)
{
struct dns_session *ds = (struct dns_session *)context;
static struct task *dns_process_query_exp(struct task *t, void *context, unsigned int state)
{
struct dns_session *ds = (struct dns_session *)context;
+ struct dns_stream_server *dss = ds->dss;
struct dns_query *query, *queryb;
struct dns_query *query, *queryb;
t->expire = TICK_ETERNITY;
t->expire = TICK_ETERNITY;
LIST_DELETE(&query->list);
pool_free(dns_query_pool, query);
ds->onfly_queries--;
LIST_DELETE(&query->list);
pool_free(dns_query_pool, query);
ds->onfly_queries--;
}
else {
t->expire = query->expire;
}
else {
t->expire = query->expire;
+ if (expired) {
+ /* no response will come, release the slots */
+ HA_SPIN_LOCK(DNS_LOCK, &dss->lock);
+ ds->nb_queries -= expired;
+ LIST_DEL_INIT(&ds->list);
+ if (ds->nb_queries)
+ LIST_INSERT(&dss->free_sess, &ds->list);
+ else {
+ LIST_INSERT(&dss->idle_sess, &ds->list);
+ dss->idle_conns++;
+ }
+ HA_SPIN_UNLOCK(DNS_LOCK, &dss->lock);
+ }
+