Skip to content

feat: implement DNS resolver and query handling - #930

Open
niteshpurohit wants to merge 7 commits into
feat/adapters-ngtcp2-nghttp3from
feat/adapters-cares
Open

niteshpurohit wants to merge 7 commits into
feat/adapters-ngtcp2-nghttp3from
feat/adapters-cares

Conversation

@niteshpurohit

Copy link
Copy Markdown
Member
  • Added DnsResolver class to manage DNS queries and responses.
  • Introduced DnsQueryToken for tracking individual queries.
  • Implemented asynchronous handling of DNS queries using c-ares library.
  • Created structures for DNS addresses and nameservers to encapsulate relevant data.
  • Added error handling for various DNS operations and responses.
  • Implemented tests for DNS resolver functionality, including success, failure, and timeout scenarios.
  • Ensured that all new structures are trivially copyable where applicable.

closes: #62
closes: #59

- Added DnsResolver class to manage DNS queries and responses.
- Introduced DnsQueryToken for tracking individual queries.
- Implemented asynchronous handling of DNS queries using c-ares library.
- Created structures for DNS addresses and nameservers to encapsulate relevant data.
- Added error handling for various DNS operations and responses.
- Implemented tests for DNS resolver functionality, including success, failure, and timeout scenarios.
- Ensured that all new structures are trivially copyable where applicable.

closes: #62
closes: #59
@niteshpurohit niteshpurohit self-assigned this Sep 19, 2026
@niteshpurohit
niteshpurohit added this pull request to stack #915 September 19, 2026 13:27
Copilot AI lite review requested due to automatic review settings September 19, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Cancellation leaves native query slots occupied until c-ares completes, allowing canceled work to block or exhaust resolver capacity.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds an asynchronous c-ares DNS resolver adapter with bounded queries, socket/timer integration, TTL results, normalized errors, and test/build support.

Changes:

  • Introduces DNS adapter contracts and c-ares implementation.
  • Adds resolver lifecycle, nameserver configuration, cancellation, and query tests.
  • Updates dependency configuration and CI coverage.
File Description
src/​adapters/​dns.cpp c-ares resolver implementation
src/​adapters/​contract/​laghu/​adapters/​dns.hpp Public DNS contracts
tests/​adapters/​dns.cpp DNS behavior tests
tests/​adapters/​dns_contract.cpp Type contract checks
src/​core/​contract/​laghu/​core/​contract.hpp DNS dependency operations
src/​adapters/​dependency.cpp Dependency operation mapping
CMakeLists.txt DNS targets and tests
cmake/​LaghuDependencies.cmake Dependency build-state handling
.github/​workflows/​toolchain.yml Toolchain DNS coverage
.github/​workflows/​codeql.yml CodeQL DNS build coverage

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/adapters/contract/laghu/adapters/dns.hpp
Comment thread src/adapters/dns.cpp Outdated
- Added new fields to QuerySlot for better channel management.
- Improved cancellation logic to handle native query states.
- Updated address_complete and socket_state functions to manage query lifecycle more effectively.
- Enhanced tests to cover new cancellation scenarios and ensure proper query exhaustion handling.
Copilot AI review requested due to automatic review settings September 19, 2026 14:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The review found a guaranteed invalid expected-value access in tests plus resolver completion and socket-capacity lifecycle bugs.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity

Open (3)
Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Check expected error before accessing Result::value()

tests/​adapters/​dns.cpp:403

This expression calls value() on the Result returned for the 254-byte hostname. That result is intentionally an error, so the test invokes std::expected::value() without checking it and can throw/terminate instead of validating the input error. Call has_value() directly (and, ideally, assert invalid_range).

Comment thread CMakeLists.txt
Comment on lines +274 to +277
list(FIND LAGHU_EFFECTIVE_FEATURES async_dns laghu_async_dns_feature_index)
if(NOT laghu_async_dns_feature_index EQUAL -1)
add_library(laghu_dns STATIC
src/adapters/dns.cpp
Comment thread src/adapters/dns.cpp
Comment thread src/adapters/dns.cpp
- Added logic to handle socket capacity failures in the DNS resolver.
- Introduced a new flag in QuerySlot to track socket capacity issues.
- Updated the completion callback to check for inactive tokens during resolution.
- Added tests to validate behavior when socket capacity is exceeded.
- Improved overall robustness of DNS query handling under load.
Copilot AI review requested due to automatic review settings September 19, 2026 14:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Completion callbacks cannot submit replacement queries when all query slots are occupied, and timeout coverage is environment-dependent.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Reclaim completed slots before allowing reentrant submissions

src/​adapters/​dns.cpp:210

When all 64 query slots are occupied, a completion decrements outstanding but leaves its slot active/native_done until the surrounding process_events() or process_timeout() call returns. A completion sink that immediately submits a replacement query therefore sees available outstanding capacity but gets exhaustion because the slot scan below skips the completed slot. Finalize/reclaim the completed slot before allowing reentrant submissions, while ensuring the outer event-loop path cannot retire a newly reused slot.

Low severity Make timeout test deterministic and assert native timeout status

tests/​adapters/​dns.cpp:368

This purported timeout test targets 127.0.0.1:9, which commonly fails immediately with ARES_ECONNREFUSED, and only checks the broad io error. On a host where the port is closed it never exercises ARES_ETIMEOUT, process_timeout(), or timeout normalization; on a filtered host the result changes. Use a fixture that receives and drops the DNS packet (or otherwise assert the native timeout status) so this coverage is deterministic.

- Added support for asynchronous DNS resolution by introducing new properties in QuerySlot.
- Implemented completion handling for queries to allow reentrant submissions.
- Updated tests to validate the new asynchronous behavior and ensure proper handling of query results.
Copilot AI review requested due to automatic review settings September 19, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The resolver currently uses a c-ares typedef/API compatibility issue and a warning-as-error TTL comparison that prevent clean supported builds.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)

Comment thread src/adapters/dns.cpp Outdated
Comment thread src/adapters/dns.cpp
- Changed the type of the channel member in QuerySlot from ares_channel_t* to ares_channel.
- This change simplifies the management of the DNS channel within the QuerySlot structure.
Copilot AI review requested due to automatic review settings September 19, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Batched event and timeout processing can dereference freed resolver state after a reentrant completion callback destroys or replaces the resolver.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 1 Medium severity

Open (4)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Low severity Define callback behavior for queries canceled during teardown

src/​adapters/​contract/​laghu/​adapters/​dns.hpp:98

This says completion callbacks are synchronous with destruction, but release() sets shutting_down and drops outstanding c-ares queries without calling DnsQuerySink::complete. Consumers following this contract may wait for callbacks that never arrive; document the destruction behavior explicitly or dispatch cancellation results during teardown.

Comment thread src/adapters/dns.cpp
Comment thread src/adapters/dns.cpp
- Updated comments to clarify that destruction of the resolver abandons outstanding queries without invoking their completion callbacks.
- Modified `process_events` and `process_timeout` methods to return early if the query is done or if socket capacity fails, improving clarity and flow.
- Added tests to verify that the resolver can be destroyed during event and timeout callbacks, ensuring proper resource management.
Copilot AI review requested due to automatic review settings September 19, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The system-resolver configuration path is constructed but never exercised by a real lookup test.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (3)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Test system resolver configuration path

tests/​adapters/​dns.cpp:522

This only constructs a resolver with an empty nameserver list; every actual lookup in query_fixture supplies an explicit server. Consequently the nameservers.empty() path is never exercised through ares_getaddrinfo, so system resolver configuration can regress without detection despite being an adapter acceptance criterion. Add a lookup that drives the system configuration path (or a controllable system-resolver fixture).

- Introduced a new test case for system resolver lookup.
- Validates the resolver's ability to resolve "localhost" to the correct IPv4 address.
- Ensures that the resolver functions correctly under expected conditions.
Copilot AI review requested due to automatic review settings September 19, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

c-ares library initialization is missing for the declared supported 1.20.0 system floor, so DNS creation can fail on supported installations.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)

Comment thread src/adapters/dns.cpp
Comment on lines +278 to +281
const int initialized = ares_init_options(&query.channel, &options, option_mask);
if (initialized != ARES_SUCCESS) {
return std::unexpected{native_error(core::DependencyOperation::dns_session,
initialized, state.log)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create the c-ares async DNS adapter Create protocol and DNS adapter contracts

2 participants