GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DnsQueryContext.writeQuery does not return after failing the query when the ID space is exhausted · Issue #16948 · netty/netty

DnsQueryContext.writeQuery does not return after failing the query when the ID space is exhausted #16948

New issue
Copy link
New issue
Copy link
Closed
#16950
Closed
DnsQueryContext.writeQuery does not return after failing the query when the ID space is exhausted#16948
#16950
Copy link
Milestone
4.2.16.Final

Description

@HwangRock
HwangRock
opened on Jun 13, 2026
Issue body actions

I came across what looks like a missing return in DnsQueryContext.writeQuery(boolean). In the branch that handles an exhausted query-ID space, the method fails the query but then keeps executing instead of returning:

netty/resolver-dns/src/main/java/io/netty/resolver/dns/DnsQueryContext.java

Lines 176 to 181 in 7bae566

if ((id = queryContextManager.add(nameServerAddr, this)) == -1) {
// We did exhaust the id space, fail the query
IllegalStateException e = new IllegalStateException("query ID space exhausted: " + question());
finishFailure("failed to send a query via " + protocol(), e, false);
queryLifecycleObserver.queryWritten(nameServerAddr, channel.newFailedFuture(e));
}

When queryContextManager.add(...) returns -1, the query is failed via finishFailure(...), but execution falls through: the completion listener is registered, newQuery(-1, ...) is called, and sendQuery(...) ends up writing an already-failed query to the wire with id -1 (the encoder truncates it to 65535). The listener then calls removeFromContextManager(-1) for an id that was never stored, which trips an assertion when assertions are enabled.

I reproduced it by exhausting the id space for a single nameserver (65536 in-flight queries) and calling writeQuery once more. A query is still written to the channel even though the promise is already failed:

expected: <null> but was: <DatagramDnsQuery(to: localhost/127.0.0.1:53, id: 65535, QUERY(0), RD)>

and the completion listener throws:

java.lang.AssertionError: DnsQueryContext not found, id: -1
	at io.netty.resolver.dns.DnsQueryContextManager$DnsQueryContextMap.remove(DnsQueryContextManager.java:186)
	at io.netty.resolver.dns.DnsQueryContextManager.remove(DnsQueryContextManager.java:85)
	at io.netty.resolver.dns.DnsQueryContext.removeFromContextManager(DnsQueryContext.java:234)
	at io.netty.resolver.dns.DnsQueryContext.lambda$writeQuery$0(DnsQueryContext.java:206)
	at io.netty.resolver.dns.DnsQueryContext.writeQuery(DnsQueryContext.java:184)

This looks like it changed with #15812, where the branch previously did return channel.newFailedFuture(e);. Adding a return; after the queryWritten(...) call appears to restore the earlier behaviour. I'd be happy to open a PR.

Activity

  1. normanmaurer
    added this to the 4.2.16.Final milestone on Jun 15, 2026
  2. normanmaurer
    added a commit that references this issue on Jun 15, 2026

    Return early in DnsQueryContext.writeQuery when the query ID space is…

    This issue will close once commit ec35cbe is merged into the '4.2' branch.
    ec35cbe
  3. normanmaurer
    closed this as completedin #16950on Jun 15, 2026
  4. normanmaurer
    added a commit that references this issue on Jun 16, 2026

    Auto-port 5.0: Return early in DnsQueryContext.writeQuery when the qu…

    This issue will close once commit f622712 is merged into the '4.2' branch.
    f622712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.2.16.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.