-
Notifications
You must be signed in to change notification settings - Fork 53
fix(sandbox): stop the dev-server probe leaking a keep-alive connection every tick #6830
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 |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package probe | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "runtime" | ||
| "strconv" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| // TestHeadDoesNotLeakKeepAliveGoroutine guards against regressing to a | ||
| // per-tick Transport that leaves an idle keep-alive connection (and its | ||
| // readLoop goroutine) open forever, since head() is called repeatedly for | ||
| // the life of the daemon. | ||
| func TestHeadDoesNotLeakKeepAliveGoroutine(t *testing.T) { | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| w.WriteHeader(200) | ||
| })) | ||
| defer srv.Close() | ||
|
|
||
| port, err := strconv.Atoi(srv.URL[len("http://127.0.0.1:"):]) | ||
| if err != nil { | ||
| t.Fatalf("parse port from %q: %v", srv.URL, err) | ||
| } | ||
|
|
||
| before := runtime.NumGoroutine() | ||
|
Contributor
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. P3: This asserts on the global Prompt for AI agents |
||
|
|
||
| for i := 0; i < 20; i++ { | ||
| status, _, up := head(port) | ||
| if !up || status != 200 { | ||
| t.Fatalf("head() = status=%d up=%v, want 200/true", status, up) | ||
| } | ||
| } | ||
|
|
||
| // Idle keep-alive readLoop goroutines don't exit synchronously; give them | ||
| // a moment, then assert we haven't accumulated one per call. | ||
| deadline := time.Now().Add(2 * time.Second) | ||
| for { | ||
| if runtime.NumGoroutine() <= before+5 { | ||
| return | ||
| } | ||
| if time.Now().After(deadline) { | ||
| t.Fatalf("goroutine count grew from %d to %d after 20 head() calls — keep-alive connections are leaking", | ||
| before, runtime.NumGoroutine()) | ||
| } | ||
| time.Sleep(10 * time.Millisecond) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: On IPv6-only hosts, this port extraction fails because
httptest.NewServercan return a URL such ashttp://[::1]:<port>. Parsesrv.URLwithnet/urlandnet.SplitHostPortso the regression test works on every loopback address supported byDialLoopback.Prompt for AI agents