Skip to content

Commit a87e1c1

Browse files
h4x3rotabclaude
andcommitted
fix(ingress): eliminate 5s latency from HAProxy evidence routing
The evidence-server routing used payload(0,0) to inspect request bytes. Per HAProxy docs, length=0 means "extract to end of buffer", which in TCP mode defers rule evaluation until the full inspect-delay (5s) expires — HAProxy cannot know when a raw TCP stream ends. This added a 5-second latency to every TLS connection, making the service appear broken for users. Fix: use payload(0,16) with a concrete byte count (16 = len of "HEAD /evidences", the longest prefix matched) and accept once req.len >= 16. After SSL termination a full TLS record is decrypted atomically, so these 16 bytes arrive instantly. Before: ~5.2s per request (TLS 0.2s + inspect-delay 5.0s) After: ~0.28s per request (TLS 0.2s + routing ~0.04s) Tested on a live Phala CVM with Route53 DNS — both normal requests and /evidences endpoint verified working. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 43da63b commit a87e1c1

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

custom-domain/dstack-ingress/scripts/entrypoint.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,16 @@ EOF
156156
cat <<'EVIDENCE_BLOCK' >>/etc/haproxy/haproxy.cfg
157157
158158
# Route /evidences requests to the local evidence HTTP server.
159-
# inspect-delay sets the upper bound for buffering; the accept rule
160-
# fires as soon as any application data is present in the buffer
161-
# (after SSL termination a full TLS record is decrypted atomically,
162-
# so the complete HTTP request is available on first evaluation).
159+
# accept fires once 16 bytes have arrived — enough for the
160+
# longest prefix we match ("HEAD /evidences" = 16 chars).
161+
# Using req.len with a concrete threshold is critical: the
162+
# previous payload(0,0) (length 0 = "whole buffer") deferred
163+
# evaluation until the full inspect-delay because HAProxy
164+
# cannot know when a TCP stream ends.
163165
tcp-request inspect-delay 5s
164-
tcp-request content accept if { req.len gt 0 }
165-
acl is_evidence payload(0,0) -m beg "GET /evidences"
166-
acl is_evidence payload(0,0) -m beg "HEAD /evidences"
166+
tcp-request content accept if { req.len ge 16 }
167+
acl is_evidence payload(0,16) -m beg "GET /evidences"
168+
acl is_evidence payload(0,16) -m beg "HEAD /evidences"
167169
use_backend be_evidence if is_evidence
168170
EVIDENCE_BLOCK
169171
fi

0 commit comments

Comments
 (0)