host: reproduce step 1's lost Connection: close without root
Run 4 of the W6 ingress drain witness saw no Connection: close on 761 responses during the drain. The loop's detection is sound (resp.Close on HTTP/1.1, through the tracked :443 server); the header is lost in the edge: for a gzip-accepting client, gzipWriter.syncHeader replaces the real writer's headers wholesale, dropping what connDrain.track set. TestIngressRootEdgeStep1ConnectionClose shows detection and the identity path passing and the gzip path failing until the edge keeps the header.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+84
−0
internal/host/ingressdrain_rootrunner_linux_test.go+84 −0
diff --git a/internal/host/ingressdrain_rootrunner_linux_test.go b/internal/host/ingressdrain_rootrunner_linux_test.go| index c6106858a..ab624d91d 100644 |
| --- a/internal/host/ingressdrain_rootrunner_linux_test.go |
| +++ b/internal/host/ingressdrain_rootrunner_linux_test.go |
| @@ -31,12 +31,15 @@ package host |
| import ( |
| "bufio" |
| "context" |
| + "crypto/tls" |
| "encoding/json" |
| "errors" |
| "fmt" |
| "io" |
| "log" |
| + "net" |
| "net/http" |
| + "net/http/httptest" |
| "net/http/httptrace" |
| "os" |
| "os/exec" |
| @@ -53,9 +56,11 @@ import ( |
| "testing" |
| "time" |
| + "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/hadeparture" |
| "github.com/carlosframework/platform/internal/ingresshealth" |
| "github.com/carlosframework/platform/internal/lease" |
| + "github.com/carlosframework/platform/internal/registry" |
| ) |
| const ( |
| @@ -1129,3 +1134,82 @@ func TestIngressRootDepartureSeam(t *testing.T) { |
| t.Fatal("the termination consumer did not start on the fixture queue") |
| } |
| } |
| + |
| +// Step 1's Connection: close as the request loop sees it, without root. |
| +// Run 4 saw 761 responses served during the drain and none with |
| +// Connection: close. The first two cases show the loop's detection works |
| +// (the loop's client shape reads resp.Close; the real edge's step 1 does |
| +// set the header on an identity response). The third is the production |
| +// finding: a client that accepts gzip, as Go's client does by default and |
| +// browsers do, gets the response through internal/edge's gzipWriter, whose |
| +// syncHeader replaces the real writer's header block wholesale with its |
| +// private map, and the Connection: close set by connDrain.track before it |
| +// is gone. It fails until the edge keeps that header. |
| +func TestIngressRootEdgeStep1ConnectionClose(t *testing.T) { |
| + t.Run("client-detection", func(t *testing.T) { |
| + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Connection", "close") |
| + io.WriteString(w, "lifecycle tenant") |
| + })) |
| + srv.EnableHTTP2 = true |
| + srv.StartTLS() |
| + defer srv.Close() |
| + addr := srv.Listener.Addr().String() |
| + // coldRootClient's shape: a custom TLS config and dialer. |
| + client := &http.Client{Transport: &http.Transport{TLSClientConfig: &tls.Config{RootCAs: srv.Client().Transport.(*http.Transport).TLSClientConfig.RootCAs}, DialContext: func(ctx context.Context, network, _ string) (net.Conn, error) { |
| + return (&net.Dialer{}).DialContext(ctx, network, addr) |
| + }}} |
| + defer client.CloseIdleConnections() |
| + resp, err := client.Get("https://example.com/") |
| + lifecycleCheck(t, "request", err) |
| + ok, detail := ingressRootRead(resp) |
| + if !ok || resp.ProtoMajor != 1 || !resp.Close { |
| + t.Fatalf("the loop's client: %s %s close=%v", resp.Proto, detail, resp.Close) |
| + } |
| + }) |
| + for _, c := range []struct{ name, encoding string }{{"edge-identity", "identity"}, {"edge-gzip-accepted", ""}} { |
| + t.Run(c.name, func(t *testing.T) { |
| + dir, err := os.MkdirTemp("", "w6close") |
| + lifecycleCheck(t, "scratch", err) |
| + t.Cleanup(func() { os.RemoveAll(dir) }) |
| + sock := filepath.Join(dir, "app.sock") |
| + ln, err := net.Listen("unix", sock) |
| + lifecycleCheck(t, "tenant socket", err) |
| + tenant := &http.Server{Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "lifecycle tenant") })} |
| + go tenant.Serve(ln) |
| + t.Cleanup(func() { tenant.Close() }) |
| + reg, err := registry.Open(filepath.Join(dir, "registry.db")) |
| + lifecycleCheck(t, "registry", err) |
| + t.Cleanup(func() { reg.Close() }) |
| + lifecycleCheck(t, "route", reg.Upsert(registry.Route{Host: "app.example.com", Socket: sock})) |
| + e, err := edge.New(reg, nil) |
| + lifecycleCheck(t, "edge", err) |
| + srv := httptest.NewServer(e) |
| + defer srv.Close() |
| + // Go's client asks for gzip by itself unless told otherwise. |
| + client := &http.Client{Transport: &http.Transport{}} |
| + defer client.CloseIdleConnections() |
| + get := func() *http.Response { |
| + req, err := http.NewRequest("GET", srv.URL+"/", nil) |
| + lifecycleCheck(t, "request", err) |
| + req.Host = "app.example.com" |
| + if c.encoding != "" { |
| + req.Header.Set("Accept-Encoding", c.encoding) |
| + } |
| + resp, err := client.Do(req) |
| + lifecycleCheck(t, "response", err) |
| + if ok, detail := ingressRootRead(resp); !ok { |
| + t.Fatalf("tenant: %s", detail) |
| + } |
| + return resp |
| + } |
| + if resp := get(); resp.Close { |
| + t.Fatal("Connection: close before the drain") |
| + } |
| + lifecycleCheck(t, "step 1", e.BeginIngressDrain()) |
| + if resp := get(); !resp.Close { |
| + t.Fatalf("step 1 served without Connection: close (Accept-Encoding %q)", c.encoding) |
| + } |
| + }) |
| + } |
| +} |