-
Notifications
You must be signed in to change notification settings - Fork 42
Fix: bound daemon HTTP connections and avoid protobuf lock copies #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,29 @@ import ( | |
| "github.com/samber/do/v2" | ||
| ) | ||
|
|
||
| func TestDaemonServerConfiguresConnectionLimits(t *testing.T) { | ||
| listener, err := net.Listen("tcp", "127.0.0.1:0") | ||
| if err != nil { | ||
| t.Fatalf("listen tcp: %v", err) | ||
| } | ||
| servers := &daemonServers{} | ||
| servers.add("HTTP_LISTEN", listener.Addr().String(), listener, http.NewServeMux(), nil) | ||
| server := servers.items[0].server | ||
| if server.ReadHeaderTimeout != 5*time.Second || server.IdleTimeout != 2*time.Minute || server.MaxHeaderBytes != 64<<10 { | ||
| t.Fatalf("server limits = header %s idle %s max-header %d", server.ReadHeaderTimeout, server.IdleTimeout, server.MaxHeaderBytes) | ||
| } | ||
| if server.WriteTimeout != 0 { | ||
| t.Fatalf("server WriteTimeout = %s, want zero for long-running streams", server.WriteTimeout) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 新增测试未覆盖实际改动(http2.Server 超时清零),已确认的长连接回归仍无测试保护本次改动的实际行为变化是把 h2c.NewHandler 的 http2.Server 配置由带显式超时(IdleTimeout 2m、ReadIdleTimeout 30s、PingTimeout 15s、WriteByteTimeout 30s)改为零值 &http2.Server{},以避免 HTTP/2 层超时主动中断长时间运行的 Connect attach bidi 会话——这正是历史已确认问题(66a7dab3)所指向的回归,本次为修复。但新增测试只断言 http.Server.WriteTimeout == 0,该字段本就不曾设置、保持 0,并不属于本次改动;真正被清零的 http2.Server 字段被封装在 h2c.NewHandler 内部,现有测试(包括 TestDaemonTCPServerAttachAgentRunBidiUsesH2C)都无法感知。若后续有人再次以"加固"名义给 http2.Server 加上 ReadIdleTimeout/WriteByteTimeout/IdleTimeout,测试仍会全部通过,该文件历史上已经发生过一次反复(先加超时、本次移除),因此回归风险是具体且已被证实的。另外需注意:x/net 对零值 http2.Server 会把 WriteByteTimeout 回退为默认 15s,即写阻塞断连阈值从 30s 收紧到 15s,与该改动"保护长流"的目标存在细微张力,值得显式决策并在测试/注释中固化。 Problem code: Recommendation: |
||
| config := servers.items[0].h2c | ||
| if config == nil || config.IdleTimeout != 0 || config.ReadIdleTimeout != 0 || config.PingTimeout != 0 || config.WriteByteTimeout != 0 { | ||
| t.Fatalf("h2c connection limits = %#v, want all zero for long-running streams", config) | ||
| } | ||
| if err := servers.shutdown(context.Background()); err != nil { | ||
| t.Fatalf("shutdown server: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestDaemonTCPServerAttachAgentRunBidiUsesH2C(t *testing.T) { | ||
| seen := make(chan string, 1) | ||
| mux := http.NewServeMux() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.