{"record":{"id":"35479b88c1db7f28","repo":"XX-net/XX-Net","slug":"query-over-tcp-s-type-s-timeout","errorCode":null,"errorMessage":"query_over_tcp %s type:%s timeout","messagePattern":"query_over_tcp (.+?) type:(.+?) timeout","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/smart_router/local/dns_query.py","lineNumber":456,"sourceCode":"                xlog.warn(\"query_over_tcp for %s type:%d return none, cost:%f\", domain, dns_type, t2-t0)\n\n            ips = []\n            for r in p.rr:\n                ip = utils.to_bytes(str(r.rdata))\n                if not utils.check_ip_valid(ip) and dns_type != 2:\n                    if ip == domain:\n                        continue\n\n                    ip_ips = self.query(ip, dns_type)\n                    ips += ip_ips\n                else:\n                    ips.append(ip)\n\n            xlog.debug(\"DNS %s %s return %s t:%f\", self.protocol, domain, ips, t2-t0)\n            self.connections.append([sock, time.time()])\n            return ips\n        except socket.timeout:\n            xlog.warn(\"query_over_tcp %s type:%s timeout\", domain, dns_type)\n            return []\n        except Exception as e:\n            xlog.exception(\"query_over_tcp %s type:%s except:%r\", domain, dns_type, e)\n            return []\n\n\nclass DnsOverTlsQuery(DnsOverTcpQuery):\n    def __init__(self, server_list=None):\n        if not server_list:\n            server_list = [\n                {\n                    \"domain\": \"one.one.one.one\",\n                    \"ipv4s\": [b\"1.1.1.1\", b\"1.0.0.1\"],\n                },\n                {\n                    \"domain\": \"dns.quad9.net\",\n                    \"ipv4s\": [b\"9.9.9.9\", b\"149.112.112.112\"],\n                }","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/dns_query.py#L438-L474","documentation":"The TCP DNS query raised socket.timeout — either while connecting, sending, or within the recv loop — so the query is abandoned and [] returned. The socket is not returned to the connection pool. This indicates the server (or a middlebox) did not respond within the client timeout.","triggerScenarios":"Calling query() when the DNS server does not answer within the socket timeout: overloaded server, packet-filtering firewall silently dropping TCP 53/853, or a pooled connection that was silently closed so recv blocks forever until timeout.","commonSituations":"Firewalls that DROP rather than REJECT (client hangs until timeout), idle pooled connections killed by NAT/middleboxes, slow or rate-limiting resolvers, mobile networks.","solutions":["Increase the timeout passed to the client (default is small; construct with a larger timeout)","Verify reachability with 'dig +tcp @server domain' and time it","Use shorter connection-pool reuse (drop connections older than a few seconds) so stale sockets aren't reused","Switch to DoH/443 which is rarely filtered and has better latency characteristics"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    ips = tcp_client.query(domain, timeout=5)\nexcept socket.timeout:\n    ips = doh_client.query(domain)  # fail over transport","preventionTips":["Set an explicit, realistic timeout when constructing the TCP client","Cap connection reuse time so stale pooled sockets aren't reused","Use DoH where middleboxes silently drop TCP 53/853"],"tags":["dns","tcp","socket-timeout","recv-timeout"],"backgroundTag":"socket-timeout","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}