解决 Linkerd 报错 Protocol detection timed out 协议探测超时修复
排查 MySQL、Redis 等服务器在经过 Linkerd 网格代理时卡顿数秒,分析 Server-first 协议与 opaque ports 规避策略。
问题现象
连接注入了 Linkerd 的 MySQL 或自定义长连接服务时,客户端建立连接固定卡顿 10 秒左右,代理日志输出:
WARN [ 120.45s] proxy={server=in} linkerd_app_core::serve: Protocol detection timed out after 10s, falling back to TCP
触发根因
- Linkerd 代理默认对入站流量执行协议嗅探(Protocol Detection),等待客户端发送前几个字节以判定是 HTTP/1 还是 HTTP/2;
- MySQL / SMTP / Redis 等属于“服务端先行”(Server-first)协议,服务端等待客户端先发握手或服务端主动推送握手包,导致双方互等直至 10 秒超时。
解决步骤
使用 opaque-ports 注解标记为不透明 TCP 端口
在 Service 或 Pod 元数据中加入注解跳过探测:
metadata:
annotations:
config.linkerd.io/opaque-ports: "3306,6379"
验证确认
更新工作负载配置:
kubectl rollout restart deploy/mysql -n prod
连接建立耗时从 10 秒骤降至 1 毫秒以内,协议探测超时告警彻底消失。


