MCPcopy
hub / github.com/caddyserver/caddy / brokenUpstreamAddr

Function brokenUpstreamAddr

modules/caddyhttp/reverseproxy/retries_test.go:571–588  ·  view source on GitHub ↗

brokenUpstreamAddr returns the address of a TCP listener that accepts connections but immediately closes them, causing a transport error (not a dial error). This simulates an upstream that is reachable but broken

(t *testing.T)

Source from the content-addressed store, hash-verified

569// connections but immediately closes them, causing a transport error (not
570// a dial error). This simulates an upstream that is reachable but broken
571func brokenUpstreamAddr(t *testing.T) string {
572 t.Helper()
573 ln, err := net.Listen("tcp", "127.0.0.1:0")
574 if err != nil {
575 t.Fatalf("failed to listen: %v", err)
576 }
577 t.Cleanup(func() { ln.Close() })
578 go func() {
579 for {
580 conn, err := ln.Accept()
581 if err != nil {
582 return
583 }
584 conn.Close()
585 }
586 }()
587 return ln.Addr().String()
588}
589
590// TestTransportErrorPlaceholder verifies that the is_transport_error
591// placeholder is set to true during transport error evaluation in tryAgain()

Callers 1

Calls 6

ListenMethod · 0.80
AddrMethod · 0.80
CleanupMethod · 0.65
CloseMethod · 0.45
AcceptMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected