Home / Function/ tryToFinishResolve() — netty Function Reference

tryToFinishResolve() — netty Function Reference

Architecture documentation for the tryToFinishResolve() function in DnsResolveContext.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  b3885856_e061_0f3a_54d9_f9abe9613324["tryToFinishResolve()"]
  3bc002ec_f54e_a55f_0b37_77eac88c60db["DnsResolveContext"]
  b3885856_e061_0f3a_54d9_f9abe9613324 -->|defined in| 3bc002ec_f54e_a55f_0b37_77eac88c60db
  07f53a31_718c_c4a3_04b0_19d21f5a6af4["query()"]
  07f53a31_718c_c4a3_04b0_19d21f5a6af4 -->|calls| b3885856_e061_0f3a_54d9_f9abe9613324
  6b22df1c_91b5_21bf_29f9_518f692074d4["onResponse()"]
  6b22df1c_91b5_21bf_29f9_518f692074d4 -->|calls| b3885856_e061_0f3a_54d9_f9abe9613324
  836e4609_6a00_0ab5_76ae_511f287c23c9["isEmpty()"]
  b3885856_e061_0f3a_54d9_f9abe9613324 -->|calls| 836e4609_6a00_0ab5_76ae_511f287c23c9
  07f53a31_718c_c4a3_04b0_19d21f5a6af4["query()"]
  b3885856_e061_0f3a_54d9_f9abe9613324 -->|calls| 07f53a31_718c_c4a3_04b0_19d21f5a6af4
  f701afc3_7b98_f295_5bd8_4cbb368c0263["finishResolve()"]
  b3885856_e061_0f3a_54d9_f9abe9613324 -->|calls| f701afc3_7b98_f295_5bd8_4cbb368c0263
  8ad22f82_2828_32a5_2cf2_ae4ca594c709["size()"]
  b3885856_e061_0f3a_54d9_f9abe9613324 -->|calls| 8ad22f82_2828_32a5_2cf2_ae4ca594c709
  style b3885856_e061_0f3a_54d9_f9abe9613324 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java lines 1014–1079

    private void tryToFinishResolve(final DnsServerAddressStream nameServerAddrStream,
                                    final int nameServerAddrStreamIndex,
                                    final DnsQuestion question,
                                    final DnsQueryLifecycleObserver queryLifecycleObserver,
                                    final Promise<List<T>> promise,
                                    final Throwable cause) {

        // There are no queries left to try.
        if (!completeEarly && !queriesInProgress.isEmpty()) {
            queryLifecycleObserver.queryCancelled(allowedQueries);

            // There are still some queries in process, we will try to notify once the next one finishes until
            // all are finished.
            return;
        }

        // There are no queries left to try.
        if (finalResult == null) {
            if (nameServerAddrStreamIndex < nameServerAddrStream.size()) {
                if (queryLifecycleObserver == NoopDnsQueryLifecycleObserver.INSTANCE) {
                    // If the queryLifecycleObserver has already been terminated we should create a new one for this
                    // fresh query.
                    query(nameServerAddrStream, nameServerAddrStreamIndex + 1, question,
                          newDnsQueryLifecycleObserver(question), true, promise, cause);
                } else {
                    query(nameServerAddrStream, nameServerAddrStreamIndex + 1, question, queryLifecycleObserver,
                          true, promise, cause);
                }
                return;
            }

            queryLifecycleObserver.queryFailed(NAME_SERVERS_EXHAUSTED_EXCEPTION);

            // .. and we could not find any expected records.

            // The following is of questionable benefit, but has been around for a while that
            // it may be risky to remove. Reference https://datatracker.ietf.org/doc/html/rfc8020
            // - If we receive NXDOMAIN we know the domain doesn't exist, any other lookup type is meaningless.
            // - If we receive SERVFAIL, and we attempt a CNAME that returns NOERROR with 0 answers, it may lead the
            //   call-site to invalidate previously advertised addresses.
            // Having said that, there is the case of DNS services that don't respect the protocol either
            // - An A lookup could result in NXDOMAIN but a CNAME may succeed with answers.
            // It's an imperfect world. Accept it.
            // Guarding it with a system property, as an opt-in functionality.
            if (TRY_FINAL_CNAME_ON_ADDRESS_LOOKUPS) {
                // If cause != null we know this was caused by a timeout / cancel / transport exception. In this case we
                // won't try to resolve the CNAME as we only should do this if we could not get the expected records
                // because they do not exist and the DNS server did probably signal it.
                final boolean isValidResponse =
                        cause == NXDOMAIN_CAUSE_QUERY_FAILED_EXCEPTION || cause == SERVFAIL_QUERY_FAILED_EXCEPTION;
                if ((cause == null || isValidResponse) && !triedCNAME &&
                        (question.type() == DnsRecordType.A || question.type() == DnsRecordType.AAAA)) {
                    // As the last resort, try to query CNAME, just in case the name server has it.
                    triedCNAME = true;

                    query(hostname, DnsRecordType.CNAME, getNameServers(hostname), true, promise);
                    return;
                }
            }
        } else {
            queryLifecycleObserver.queryCancelled(allowedQueries);
        }

        // We have at least one resolved record or tried CNAME as the last resort.
        finishResolve(promise, cause);
    }

Subdomains

Frequently Asked Questions

What does tryToFinishResolve() do?
tryToFinishResolve() is a function in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java.
Where is tryToFinishResolve() defined?
tryToFinishResolve() is defined in resolver-dns/src/main/java/io/netty/resolver/dns/DnsResolveContext.java at line 1014.
What does tryToFinishResolve() call?
tryToFinishResolve() calls 4 function(s): finishResolve, isEmpty, query, size.
What calls tryToFinishResolve()?
tryToFinishResolve() is called by 2 function(s): onResponse, query.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free