Skip to content

tcp: stalling a blocked dns-over-tls (port 853) flow delays every lookup of a resolver that probes DoT #260

Open

Description

@ShiroiKuma0

A flow the client blocks is held open by stall() before it is closed — up to 5 s for the first few repeats of the same uid/target, then up to 30 s. For most flows that is the point. For a flow to port 853 it is costly: the peer is usually a resolver that is waiting on that connection before it falls back to plain DNS.

Concretely, on Android with private DNS on "automatic" (the default), the system resolver opens DoT connections to the DNS servers of the VPN network. rethink-app blocks those (trapVpnPrivateDns, rule 14, "the vpn tunnel doesn't serve dns-over-tls") — and the engine then stalls each one. While that goes on, the device's lookups wait on the stalled connection and only then go to port 53.

Measured

On the engine pinned by rethink-app v0.5.8 (d3d530ea3e), dual-stack mobile data:

  • The tunnel's own DNS answers a direct query in 50–100 ms (dig @<tunnel dns>), while the same name through the system resolver takes 1–6 s.
  • Timestamped socket listings show why: each system lookup starts a new connection from the tun address to <vpn dns>:853, in ESTAB (netstack has syn-acked it) for 2.7–4.8 s, and the lookup completes when that connection goes away:
lookup 2: start 23:19:16.330 took 6068 ms
lookup 3: start 23:19:24.427 took 4084 ms
lookup 4: start 23:19:30.545 took 4076 ms
23:19:16.479 → 23:19:21.250  [tun addr]:37346 → [vpn dns]:853
23:19:24.511 → 23:19:27.190  [tun addr]:45736 → [vpn dns]:853
23:19:30.802 → 23:19:33.502  [tun addr]:45742 → [vpn dns]:853

(the lookup times include a fixed 1 s of the test tool)

  • The same blocked connection from a uid that has not been blocked recently is reset in ~40 ms — it is the stall, not the block, that costs the time.

With blocked port-853 flows closed without a stall, lookups through the system resolver take 60–150 ms on the same network.

intra/tcp.go still stalls every blocked flow alike on n2 HEAD (c2788705).

What I did

In the block path of tcpHandler.Proxy, skip h.stall(fid) when the target port is 853 and close at once; everything else is unchanged.

Patch: ShiroiKuma0@78380a5f

An alternative with the same effect for this case would be to never stall a flow whose destination is one of the tunnel's own (fake) DNS addresses, whatever the port.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions