The DNSCrypt forwarder client's TCP path does not set NoDelay and sends the length prefix and the packet separately #467

Open
opened 2026-11-14 11:28:57 -05:00 by claude · 0 comments
Owner

Found while the DNSCrypt-over-TCP benchmark (#226) was written. Not measured.

  1. DnsCryptForwarderClient.SendTcpAsync (src/dotnet/src/Ninlil.Dns.Server.Forwarding/Clients/DnsCryptForwarderClient.cs, about line 460) does not set NoDelay on its socket and writes the 2-byte length prefix and the packet as two sends. Two small writes followed by a read is the pattern in which Nagle's algorithm and the peer's delayed acknowledgement can add tens of milliseconds to a query. It is the upstream-client side (used when a DNSCrypt upstream falls back to TCP), not the listener.
    • Wanted: measure first (a loopback test resolver that acknowledges with delay, or a benchmark method), then send the prefix and the packet in one write and set NoDelay, as the plain TCP and TLS forwarder clients do (check what they do and make the three alike).
  2. DnsCryptTcpListener.cs (about lines 191-195) justifies NoDelay with pipelined batches. DNSCrypt over TCP is one transaction per connection here (the listener closes after the first answer), so the comment's reason does not apply. Correct the comment to the reason that does (a small reply on a connection that is about to close must not wait).
Found while the DNSCrypt-over-TCP benchmark (#226) was written. Not measured. 1. `DnsCryptForwarderClient.SendTcpAsync` (`src/dotnet/src/Ninlil.Dns.Server.Forwarding/Clients/DnsCryptForwarderClient.cs`, about line 460) does not set `NoDelay` on its socket and writes the 2-byte length prefix and the packet as two sends. Two small writes followed by a read is the pattern in which Nagle's algorithm and the peer's delayed acknowledgement can add tens of milliseconds to a query. It is the upstream-client side (used when a DNSCrypt upstream falls back to TCP), not the listener. - Wanted: measure first (a loopback test resolver that acknowledges with delay, or a benchmark method), then send the prefix and the packet in one write and set `NoDelay`, as the plain TCP and TLS forwarder clients do (check what they do and make the three alike). 2. `DnsCryptTcpListener.cs` (about lines 191-195) justifies `NoDelay` with pipelined batches. DNSCrypt over TCP is one transaction per connection here (the listener closes after the first answer), so the comment's reason does not apply. Correct the comment to the reason that does (a small reply on a connection that is about to close must not wait).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lantea-one/ninlil#467
No description provided.