Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught DNSServerError in call to _lookup_service #469

Open
DMRobertson opened this issue Nov 18, 2021 · 2 comments
Open

Uncaught DNSServerError in call to _lookup_service #469

DMRobertson opened this issue Nov 18, 2021 · 2 comments
Labels

Comments

@DMRobertson
Copy link
Contributor

https://sentry.matrix.org/sentry/sydent/issues/235982/?query=is%3Aunresolved

We got

DNSServerError

<Message id=59767 rCode=2 maxSize=0 flags=answer,recDes,recAv queries=[Query(b'__HOSTNAME__', 33, 1)]>

Twisted docs say that anything in https://twistedmatrix.com/documents/current/api/twisted.names.error.html may be raised. In particular, the parent class DomainError. We could account for this case by catching DomainError too and returning an appropriate status code + response.

@DMRobertson
Copy link
Contributor Author

We have code which catches DomainError and reraises.

try:
answers, _, _ = await self._lookup_service(service_name.decode())
except DNSNameError:
# TODO: cache this. We can get the SOA out of the exception, and use
# the negative-TTL value.
return []
except DomainError as e:
# We failed to resolve the name (other than a NameError)
# Try something in the cache, else rereaise
cache_entry = self._cache.get(service_name, None)
if cache_entry:
logger.warning(
"Failed to resolve %r, falling back to cache. %r", service_name, e
)
return list(cache_entry)
else:
raise e

While looking into this I observed that this code is duplicated in Synapse, see matrix-org/matrix-python-common#2 . So it seems reasonable treat this as a library function whose behaviour is not to be altered.

So let's look at the call stack instead to find a suitable place to catch the error.

DNSServerError: <Message id=51167 rCode=2 maxSize=0 flags=answer,recDes,recAv queries=[Query(b'_matrix._tcp.matrix.dagonismyfear.duckdns.org', 33, 1)]>
  File "sydent/http/servlets/__init__.py", line 184, in render
    result = await f(self, request)
  File "sydent/http/servlets/registerservlet.py", line 78, in render_POST
    1024 * 5,
  File "sydent/http/httpclient.py", line 60, in get_json
    uri.encode("utf8"),
  File "twisted/internet/defer.py", line 1658, in _inlineCallbacks
    cast(Failure, result).throwExceptionIntoGenerator, gen
  File "twisted/python/failure.py", line 500, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "sydent/http/matrixfederationagent.py", line 153, in request
    routing = yield defer.ensureDeferred(self._route_matrix_uri(parsed_uri))
  File "twisted/internet/defer.py", line 1658, in _inlineCallbacks
    cast(Failure, result).throwExceptionIntoGenerator, gen
  File "twisted/python/failure.py", line 500, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "sydent/http/matrixfederationagent.py", line 278, in _route_matrix_uri
    server_list = await self._srv_resolver.resolve_service(service_name)
  File "sydent/http/srvresolver.py", line 157, in resolve_service
    raise e
  File "sydent/http/srvresolver.py", line 142, in resolve_service
    answers, _, _ = await self._lookup_service(service_name.decode())

@DMRobertson
Copy link
Contributor Author

matrixfederationagent also appears to be library ish (shared with Synapse); see matrix-org/matrix-python-common#3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant