carlos / platform Public

dbforward e2e: the tap says how each connection ended

TestDBForwardLongRequestThroughTheEdge fails on CI, never locally: the
CLI's read is admitted, then the console logs "client gone" 1 ms
later and the CLI says the read did not finish. Something on the
CLI -> tap -> edge path closed first, and the tap only recorded byte
times. It now records each connection's open, which side ended first,
after how many bytes, and the error, and the CLI half of the test
prints that on failure.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 8fd836a92d73dc2047930ba05704c72da2ba66a1 parent a178a75
1 file changed, +26 −2
  • dbforward_e2e_test.go +26 −2

CI passed — run details

diff --git a/dbforward_e2e_test.go b/dbforward_e2e_test.go
index 211a8442a..3d589e3bc 100644
--- a/dbforward_e2e_test.go
+++ b/dbforward_e2e_test.go
@@ -392,6 +392,22 @@ type dbfTap struct {
addr string
mu sync.Mutex
down []time.Time
+ // events says how each tapped connection ended, and when, so a
+ // 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
+}
+
+func (tp *dbfTap) event(f string, args ...any) {
+ tp.mu.Lock()
+ defer tp.mu.Unlock()
+ tp.events = append(tp.events, time.Now().Format("15:04:05.000000 ")+fmt.Sprintf(f, args...))
+}
+
+func (tp *dbfTap) trace() string {
+ tp.mu.Lock()
+ defer tp.mu.Unlock()
+ return strings.Join(tp.events, "\n")
}
func newDBFTap(t *testing.T, target string, connect bool) *dbfTap {
@@ -430,25 +446,33 @@ func (tp *dbfTap) serve(c net.Conn, target string, connect bool) {
}
up, err := net.Dial("tcp", target)
if err != nil {
+ tp.event("%s: dial upstream: %v", c.RemoteAddr(), err)
return
}
defer up.Close()
+ id := c.RemoteAddr().String() + "->" + up.LocalAddr().String()
+ tp.event("%s: open", id)
go func() {
- io.Copy(up, in)
+ n, err := io.Copy(up, in)
+ tp.event("%s: client side ended after %d bytes up: %v", id, n, err)
up.(*net.TCPConn).CloseWrite()
}()
buf := make([]byte, 32<<10)
+ var total int
for {
n, err := up.Read(buf)
if n > 0 {
+ total += n
tp.mu.Lock()
tp.down = append(tp.down, time.Now())
tp.mu.Unlock()
if _, werr := c.Write(buf[:n]); werr != nil {
+ tp.event("%s: write to client after %d bytes down: %v", id, total, werr)
return
}
}
if err != nil {
+ tp.event("%s: upstream side ended after %d bytes down: %v", id, total, err)
return
}
}
@@ -505,7 +529,7 @@ func checkProgressAtTheCLI(t *testing.T, e *dbfE2E, tap *dbfTap, atLeast time.Du
err = cmd.Wait()
end := time.Now()
if err != nil || out.String() != "n\n3\n" {
- t.Fatalf("%q %v\n%s", out.String(), err, strings.Join(stderr, "\n"))
+ t.Fatalf("%q %v\n%s\ntap:\n%s", out.String(), err, strings.Join(stderr, "\n"), tap.trace())
}
if reading.IsZero() || reading.Sub(start) > time.Second {
t.Fatalf("DBF-11 after %s: %q", reading.Sub(start), stderr)