Submit an issue View all issues Source
MIR-2282

Websocket upgrades show up in ingress metrics as 200s with zero bytes, and never reach the access log

Open public
phinze phinze Opened Dec 3, 2026 Updated Dec 3, 2026

Every websocket (or other 101 Switching Protocols) request through httpingress gets recorded wrong. The cause is in how our reverse proxy handles upgrades, and it's the same with or without a WAF.

In pkg/httputil/reverseproxy.go, a 101 from the backend goes to handleUpgradeResponse and then returns. That path skips the stats Callback, so logRequestFromStats never runs and no access log line gets written for the request. The handler also hijacks the connection and writes the 101 straight to the hijacked buffer, so it never calls WriteHeader. As a result the ingress responseWriter keeps its default statusCode of 200, and bytesWritten stays 0 because the tunneled bytes go around it.

handleRequest still records an HTTP metric once serveHTTPWithMetrics returns. That return only happens when the tunnel closes, so the metric says "200, 0 bytes" with a duration as long as the whole websocket session. Long-lived sockets will skew latency numbers for any app that uses them.

What we probably want is for upgrades to record a 101, emit an access log line when the upgrade happens (not only when the socket closes), and maybe keep tunnel duration out of request-latency metrics. Tracking tunneled bytes could be a nice extra.

Found while reviewing mirendev/runtime#1461 (MIR-2272). Related: MIR-1584 (autoscaling doesn't model long-lived connections).