]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/worker: ensure ignored queries pop from http stream id queue
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 25 Aug 2020 14:44:14 +0000 (16:44 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 13 Oct 2020 10:55:26 +0000 (12:55 +0200)
daemon/worker.c

index ee9646bfbf2e0c2583c326f16ba46bb41cbf0890..f4bfaf43c1a1639bd07a3f465194a452c39ec941 100644 (file)
@@ -301,11 +301,7 @@ static struct request_ctx *request_create(struct worker_ctx *worker,
                req->qsource.stream_id = -1;
                if (req->qsource.flags.http) {
                        struct http_ctx *http_ctx = session_http_get_server_ctx(session);
-                       // TODO maybe assert?
-                       if (http_ctx && queue_len(http_ctx->streams) > 0) {
-                               req->qsource.stream_id = queue_head(http_ctx->streams);
-                               queue_pop(http_ctx->streams);
-                       }
+                       req->qsource.stream_id = queue_head(http_ctx->streams);
                }
                /* We need to store a copy of peer address. */
                memcpy(&ctx->source.addr.ip, peer, kr_sockaddr_len(peer));
@@ -1599,10 +1595,18 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt
 
        const bool is_query = (knot_wire_get_qr(pkt->wire) == 0);
        const bool is_outgoing = session_flags(session)->outgoing;
+       struct http_ctx *http_ctx = session_http_get_server_ctx(session);
+
+       if (!is_outgoing && http_ctx && queue_len(http_ctx->streams) <= 0)
+               return kr_error(ENOENT);
+
        /* Ignore badly formed queries. */
        if ((ret != kr_ok() && ret != kr_error(EMSGSIZE)) ||
            (is_query == is_outgoing)) {
-               if (!is_outgoing) the_worker->stats.dropped += 1;
+               if (!is_outgoing)
+                       the_worker->stats.dropped += 1;
+               if (!is_outgoing && http_ctx)
+                       queue_pop(http_ctx->streams);
                return kr_error(EILSEQ);
        }
 
@@ -1613,9 +1617,10 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt
        if (!is_outgoing) { /* request from a client */
                struct request_ctx *ctx = request_create(the_worker, session, peer,
                                                         knot_wire_get_id(pkt->wire));
-               if (!ctx) {
+               if (http_ctx)
+                       queue_pop(http_ctx->streams);
+               if (!ctx)
                        return kr_error(ENOMEM);
-               }
 
                ret = request_start(ctx, pkt);
                if (ret != 0) {