carlos / platform Public

tests: trace the console side of the DBForward edge hop (#897)

Diagnostics only. TestDBForwardLongRequestThroughTheEdge failed on main
at 5fac2ff1: the console logged the CLI's read admitted, then "ended
client gone" 1 ms later, and the tap saw the edge close the CLI's
connection first. Go's server cancels a request's context on any
background read error on the connection, a deadline timeout included,
so the missing evidence is what the console's connection from the edge
read and when. The console's listener in both edge rigs now records,
per accepted connection, every read error, every read deadline the
server or a handler sets, half-closes and closes. The trace prints
beside the tap trace when the CLI read fails. A passing run shows the
edge reusing one pooled connection for the direct read and the CLI's.

Merged on green tip 6bebb340 onto main b997d89b without a re-run, per agent
manager 8a3d302: no commit main gained since b997d89b touches this
branch's files, and the combined tree (local, not pushed) passes
go vet ./. and go test ./. -run '^TestDBForwardLongRequestThroughTheEdge$' -count=3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from dbforward-console-conn-trace into main.
claude agent, operated by paul@keymail.dev 3eff9a805e3836d5472e911efe63dcd0cccc6cba parent b997d89
1 file changed, +78 −2
  • dbforward_e2e_test.go +78 −2

CI failed — run details

diff --git a/dbforward_e2e_test.go b/dbforward_e2e_test.go
index 31a8b6db2..cf52eca3a 100644
--- a/dbforward_e2e_test.go
+++ b/dbforward_e2e_test.go
@@ -356,7 +356,8 @@ func throughTheEdge(readTimeout time.Duration, edgeURL *string, tap **dbfTap) fu
}
hs := console.NewHTTPServer(h)
hs.ReadTimeout = readTimeout
- go hs.Serve(ln)
+ conns := &dbfTap{}
+ go hs.Serve(traceListener{Listener: ln, tp: conns})
t.Cleanup(func() { hs.Close() })
reg, err := registry.Open(filepath.Join(t.TempDir(), "edge.db"))
if err != nil {
@@ -378,6 +379,7 @@ func throughTheEdge(readTimeout time.Duration, edgeURL *string, tap **dbfTap) fu
// The CLI's proxy is a tap in front of the edge, so the test sees
// what reaches the CLI's own socket (plan review finding 34).
tp := newDBFTap(t, es.Listener.Addr().String(), false)
+ tp.console = conns
*tap = tp
return "http://console.test", []string{"HTTP_PROXY=http://" + tp.addr, "NO_PROXY="}
}
@@ -396,6 +398,10 @@ type dbfTap struct {
// failure can tell which side closed first (#897: the CLI's read was
// admitted and then "client gone" a millisecond later, on CI only).
events []string
+ // console traces the console's side of the edge-to-console hop (each
+ // accepted connection's read errors, read deadlines and closes), so a
+ // failure also says which side ended that hop, and why.
+ console *dbfTap
}
func (tp *dbfTap) event(f string, args ...any) {
@@ -496,6 +502,69 @@ func (tp *dbfTap) longestGap(start, end time.Time) time.Duration {
return longest
}
+// traceListener and traceConn record what happens on each connection the
+// console's server accepts from the edge: read errors (Go's server cancels
+// the request's context on any background read error, a deadline timeout
+// included: net/http backgroundRead), every read deadline the server or a
+// handler sets, and closes (#897: "ended client gone" 1 ms after admitted,
+// on CI only).
+type traceListener struct {
+ net.Listener
+ tp *dbfTap
+}
+
+func (l traceListener) Accept() (net.Conn, error) {
+ c, err := l.Listener.Accept()
+ if err != nil {
+ return c, err
+ }
+ id := "edge " + c.RemoteAddr().String()
+ l.tp.event("%s: accepted", id)
+ return &traceConn{Conn: c, tp: l.tp, id: id}, nil
+}
+
+type traceConn struct {
+ net.Conn
+ tp *dbfTap
+ id string
+}
+
+func (c *traceConn) Read(b []byte) (int, error) {
+ n, err := c.Conn.Read(b)
+ if err != nil {
+ c.tp.event("%s: read returned %d bytes and %v", c.id, n, err)
+ }
+ return n, err
+}
+
+func (c *traceConn) SetReadDeadline(at time.Time) error {
+ when := "none"
+ switch {
+ case at.IsZero():
+ case at.Before(time.Now().Add(-time.Hour)):
+ when = "long ago (net/http aborting its background read)"
+ default:
+ when = "in " + time.Until(at).Round(time.Millisecond).String()
+ }
+ c.tp.event("%s: read deadline %s", c.id, when)
+ return c.Conn.SetReadDeadline(at)
+}
+
+// CloseWrite keeps the server's half-close (closeWriteAndWait), which it
+// finds by interface on the accepted connection.
+func (c *traceConn) CloseWrite() error {
+ c.tp.event("%s: the console closed its write side", c.id)
+ if cw, ok := c.Conn.(interface{ CloseWrite() error }); ok {
+ return cw.CloseWrite()
+ }
+ return nil
+}
+
+func (c *traceConn) Close() error {
+ c.tp.event("%s: closed by the console", c.id)
+ return c.Conn.Close()
+}
+
// checkProgressAtTheCLI is T7's witness at the CLI process itself (plan
// review finding 34): it runs the real CLI and needs DBF-11 on its stderr
// within a second of the process starting (stricter than the spec's "of the
@@ -534,6 +603,11 @@ func checkProgressAtTheCLI(t *testing.T, e *dbfE2E, tap *dbfTap, atLeast time.Du
for _, line := range strings.Split(tap.trace(), "\n") {
t.Logf("tap: %s", line)
}
+ if tap.console != nil {
+ for _, line := range strings.Split(tap.console.trace(), "\n") {
+ t.Logf("console conn: %s", line)
+ }
+ }
t.Fatalf("%q %v\n%s", out.String(), err, strings.Join(stderr, "\n"))
}
if reading.IsZero() || reading.Sub(start) > time.Second {
@@ -756,7 +830,8 @@ func throughBackhaul(readTimeout time.Duration, tap **dbfTap) func(t *testing.T,
}
hs := console.NewHTTPServer(h)
hs.ReadTimeout = readTimeout
- go hs.Serve(ln)
+ conns := &dbfTap{}
+ go hs.Serve(traceListener{Listener: ln, tp: conns})
t.Cleanup(func() { hs.Close() })
dir := t.TempDir()
bin := filepath.Join(dir, "edge.test")
@@ -804,6 +879,7 @@ func throughBackhaul(readTimeout time.Duration, tap **dbfTap) func(t *testing.T,
}
}()
tp := newDBFTap(t, sender, true)
+ tp.console = conns
*tap = tp
return "https://console.backhaul.test", []string{"HTTPS_PROXY=http://" + tp.addr, "NO_PROXY=", "SSL_CERT_FILE=" + filepath.Join(dir, "ca.pem")}
}