Bug: maxLatencyWriter panics on hijacked connections with OpenTelemetry enabled
Author: probelabs[bot]Created Jul 13, 2026Updated Jul 13, 2026
Labelsbugexternal
Root Cause Analysis
The crash is caused by a nil pointer dereference when the Gateway attempts to asynchronously flush an HTTP response on a hijacked connection.
- Hijacked Connection: When an API uses WebSockets, Server-Sent Events (SSE), or custom streaming, the connection is hijacked. Once hijacked, the standard Go HTTP server stops managing the connection buffer.
- Asynchronous Flush: Tyk Gateway uses a
maxLatencyWriterwhich spawns a background goroutine (delayedFlush) to periodically flush the response writer. For WebSockets and SSE, the flush interval is hardcoded to-1(flush immediately). - The Crash: When OpenTelemetry is enabled, the response writer is wrapped by
otelhttpandhttpsnoop. ThedelayedFlushgoroutine triggers a flush that propagates through this middleware chain down to the standardnet/httpandbufiopackages. Because the connection has already been hijacked, the underlying buffer is invalid (nil), resulting in a segmentation violation (SIGSEGV) whenbufio.Flushis called.
Steps to Reproduce
- Enable OpenTelemetry in
tyk.conf(opentelemetry.traces.enabled = true). - Create an API that proxies to a WebSocket backend.
- Send a WebSocket upgrade request to the Gateway.
- The Gateway will panic with a nil pointer dereference in
maxLatencyWriter.delayedFlush.
A test case has been added in gateway/reproduce_panic_test.go that reproduces this exact scenario.
Impact
Gateway crashes in production when OpenTelemetry is enabled and WebSocket/SSE traffic is processed.
Workaround
Disable OpenTelemetry globally until the bug is fixed. There is no API-level override to disable OpenTelemetry for specific APIs.
Source: TykTechnologies/tyk