From: Tomas Krizek Date: Tue, 25 Aug 2020 14:44:14 +0000 (+0200) Subject: daemon/worker: ensure ignored queries pop from http stream id queue X-Git-Tag: v5.2.0~15^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a728f011535f0d2a64507fa25f1232cbaf4b0793;p=thirdparty%2Fknot-resolver.git daemon/worker: ensure ignored queries pop from http stream id queue --- diff --git a/daemon/worker.c b/daemon/worker.c index ee9646bfb..f4bfaf43c 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -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) {