Skip to content

Comments

Add comprehensive DNS request logging to debug unhandled errors#12

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-10
Draft

Add comprehensive DNS request logging to debug unhandled errors#12
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-10

Conversation

Copy link

Copilot AI commented Aug 31, 2025

This PR addresses unhandled DNS query errors that were causing server crashes and missing Sentry logging. The issue manifested as:

File "/usr/local/lib/python2.7/site-packages/twisted/names/common.py", line 78, in query
    return defer.maybeDeferred(method, query.name.name, timeout)

Problem

"Weird DNS/53 requests" were causing unhandled errors in the DNS query processing pipeline. These errors occurred when malformed or unexpected DNS queries tried to access query.name.name, leading to AttributeError exceptions that weren't being caught or logged properly, thus missing Sentry reporting.

Solution

Enhanced the Resolver.query() method in dns/networking.py with comprehensive logging and robust error handling:

🔍 Comprehensive Request Logging

  • INFO level: All incoming DNS queries are now logged with full details
  • DEBUG level: Query type, class, and extracted domain names
  • WARNING level: Malformed queries that fail name extraction
  • ERROR level: Unexpected errors (will reach Sentry as intended)

🛡️ Robust Error Handling

  • Safe extraction of query.name.name with proper exception handling
  • Graceful handling of AttributeError for malformed queries
  • Proper byte string to string conversion for database lookups
  • Catch-all exception handler to prevent unhandled errors

📋 Example Log Output

[INFO] Received DNS query: <Query example.com A IN>
[DEBUG] Query details - type: 1, class: 1
[DEBUG] Query name: b'example.com'
[WARNING] Failed to extract query name: 'MalformedQuery' object has no attribute 'name', query object: MalformedQuery

Benefits

  1. Visibility: All DNS requests are now logged, making it easy to identify problematic queries
  2. Debugging: Detailed query information helps diagnose the source of weird requests
  3. Reliability: Malformed queries no longer cause unhandled errors
  4. Monitoring: ERROR level logs now properly reach Sentry for alerting
  5. Minimal Impact: Changes are surgical and don't affect normal DNS resolution performance

The implementation ensures that all "weird DNS/53 requests" are captured and handled gracefully while maintaining full compatibility with existing functionality.

Fixes #10.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI self-assigned this Aug 31, 2025
Co-authored-by: garncarz <7193375+garncarz@users.noreply.github.com>
Copilot AI changed the title [WIP] Weird DNS/53 request Add comprehensive DNS request logging to debug unhandled errors Aug 31, 2025
Copilot AI requested a review from garncarz August 31, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird DNS/53 request

2 participants