carlos / platform Public

edge-roll-blip: keep unrelated dial errors at the hold deadline; isolate the cancel test

retryLocalDial and dialGenUntil filed any non-retryable error as
errHoldExpired when the attempt ctx had ended. A shared cutByDeadline
helper now does that only for deadline-shaped errors, so a peer mismatch
or control-endpoint refusal at the deadline keeps its identity.
TestProbedClientCancelDuringHoldDoesNotEject signals only for the request
dial (ctx marker), so a prober dial cannot satisfy it. Census overlay
re-pinned for the internal/edge envelope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 54e35662d766b6b54ff555e03bfa6e21dab1470a parent f5993f5
6 files changed, +102 −6
  • internal/edge/genproxy.go +1 −1
  • internal/edge/genproxy_test.go +22 −0
  • internal/edge/localhold.go +21 −2
  • internal/edge/localhold_probed_test.go +13 −2
  • internal/edge/localhold_test.go +44 −0
  • internal/provision/testdata/plan14-root-reads-edge-roll-blip.tsv +1 −1
diff --git a/internal/edge/genproxy.go b/internal/edge/genproxy.go
index 3c2779c9b..eb29f0f4b 100644
--- a/internal/edge/genproxy.go
+++ b/internal/edge/genproxy.go
@@ -109,7 +109,7 @@ func dialGenUntil(ctx context.Context, deadline time.Time, d *net.Dialer, src Ge
return nil, err
}
retryable := isRetryableDialErr(err)
- if cut && !retryable {
+ if !retryable && cutByDeadline(cut, err) {
return nil, errHoldExpired
}
left := time.Until(deadline)
diff --git a/internal/edge/genproxy_test.go b/internal/edge/genproxy_test.go
index 3157e7ccc..d7cc7c742 100644
--- a/internal/edge/genproxy_test.go
+++ b/internal/edge/genproxy_test.go
@@ -16,6 +16,8 @@ import (
"syscall"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/unixdial"
)
// fakeGens is a GenSource a test drives by hand: switchTo is plan 3's
@@ -545,3 +547,23 @@ func TestDialGenAttemptEndsAtTheDeadline(t *testing.T) {
t.Fatalf("returned after %v, want about 300ms", took)
}
}
+
+// A dial that outlasts the deadline and then fails for its own reason (a
+// listener bound to another path) keeps that reason.
+func TestDialGenKeepsUnrelatedErrorAtDeadline(t *testing.T) {
+ dir := genSockDir(t)
+ own := GenInfo{Socket: filepath.Join(dir, "x.sock"), N: 1}
+ src := newFakeGens(true)
+ src.switchTo("inst.example.com", own)
+ d := &net.Dialer{ControlContext: func(ctx context.Context, _, _ string, _ syscall.RawConn) error {
+ <-ctx.Done()
+ return unixdial.ErrPeerMismatch
+ }}
+ _, err := dialGenUntil(context.Background(), time.Now().Add(200*time.Millisecond), d, src, "inst.example.com", own)
+ if !errors.Is(err, unixdial.ErrPeerMismatch) {
+ t.Fatalf("err = %v, want ErrPeerMismatch", err)
+ }
+ if errors.Is(err, errHoldExpired) || errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("err = %v, an unrelated error is not a hold timeout", err)
+ }
+}
diff --git a/internal/edge/localhold.go b/internal/edge/localhold.go
index af647dea6..b6692f84f 100644
--- a/internal/edge/localhold.go
+++ b/internal/edge/localhold.go
@@ -2,9 +2,11 @@ package edge
import (
"context"
+ "errors"
"fmt"
"net"
"net/netip"
+ "os"
"time"
)
@@ -50,6 +52,22 @@ func isLocalUpstream(addr string) bool {
// proxyCause files it as a timeout.
var errHoldExpired = fmt.Errorf("edge: local upstream hold expired: %w", context.DeadlineExceeded)
+// cutByDeadline reports whether err is the attempt's own deadline talking:
+// the attempt context had ended (cut) and err is what a dial returns when
+// that ends it (a context error, or a timeout from the net or os layer).
+// An unrelated error that merely lands at the deadline (a peer mismatch,
+// a refused control endpoint) is not, and keeps its identity.
+func cutByDeadline(cut bool, err error) bool {
+ if !cut {
+ return false
+ }
+ if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) || errors.Is(err, os.ErrDeadlineExceeded) {
+ return true
+ }
+ var ne net.Error
+ return errors.As(err, &ne) && ne.Timeout()
+}
+
// localDialStep is the pause between attempts.
const localDialStep = 100 * time.Millisecond
@@ -59,7 +77,8 @@ const localDialStep = 100 * time.Millisecond
// context that ends at deadline and each wait is min(100ms, time left), so
// nothing outlives the hold. It always makes the first attempt. At the
// deadline it returns the last retryable error; an attempt the deadline cut
-// short gives errHoldExpired. A cancelled ctx returns ctx's error.
+// short (and failed with its deadline error) gives errHoldExpired; any
+// other non-retryable error is returned as it is. A cancelled ctx returns ctx's error.
func retryLocalDial(ctx context.Context, deadline time.Time, attempt func(context.Context) (net.Conn, error)) (net.Conn, error) {
for {
actx, cancel := context.WithDeadline(ctx, deadline)
@@ -73,7 +92,7 @@ func retryLocalDial(ctx context.Context, deadline time.Time, attempt func(contex
return nil, ctx.Err()
}
retryable := isRetryableDialErr(err)
- if cut && !retryable {
+ if !retryable && cutByDeadline(cut, err) {
return nil, errHoldExpired
}
if !retryable {
diff --git a/internal/edge/localhold_probed_test.go b/internal/edge/localhold_probed_test.go
index 1b2ad1154..20feb2257 100644
--- a/internal/edge/localhold_probed_test.go
+++ b/internal/edge/localhold_probed_test.go
@@ -419,12 +419,23 @@ func TestProbedClientCancelDuringHoldDoesNotEject(t *testing.T) {
hold := probedHold()
var plain net.Dialer
// entered: the dial is parked on the remote. dialAborted: that attempt saw
- // its context end, i.e. the cancel reached the attempt's context.
+ // its context end, i.e. the cancel reached the attempt's context. The
+ // prober's transport dials through hold.dialer too, and its first probe
+ // tick runs whatever the health says, so only a dial whose context
+ // carries requestDialKey (set on the test's own DialContext call below)
+ // signals: a probe cannot satisfy either channel.
+ type requestDialKey struct{}
entered := make(chan struct{})
dialAborted := make(chan struct{})
var enteredOnce, abortedOnce sync.Once
hold.dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
if addr == remote {
+ if ctx.Value(requestDialKey{}) == nil {
+ // A probe of the remote: it hangs like the request's dial
+ // but signals nothing.
+ <-ctx.Done()
+ return nil, ctx.Err()
+ }
enteredOnce.Do(func() { close(entered) })
<-ctx.Done()
abortedOnce.Do(func() { close(dialAborted) })
@@ -444,7 +455,7 @@ func TestProbedClientCancelDuringHoldDoesNotEject(t *testing.T) {
t.Fatal("multiProxy transport is not an *http.Transport")
}
- ctx, cancel := context.WithCancel(context.Background())
+ ctx, cancel := context.WithCancel(context.WithValue(context.Background(), requestDialKey{}, true))
defer cancel()
type result struct {
conn net.Conn
diff --git a/internal/edge/localhold_test.go b/internal/edge/localhold_test.go
index a4ecdcb5e..314a4b996 100644
--- a/internal/edge/localhold_test.go
+++ b/internal/edge/localhold_test.go
@@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/http/httptest"
+ "os"
"runtime"
"strings"
"sync"
@@ -18,6 +19,7 @@ import (
"github.com/carlosframework/platform/internal/apperr"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/unixdial"
)
// noHold is D10 off: today's transport, an instant 502 on a refused loopback
@@ -95,6 +97,48 @@ func TestRetryLocalDialBlockingAttemptEndsAtDeadline(t *testing.T) {
}
}
+// An attempt that waits out its deadline and then fails for a reason of
+// its own keeps that reason: the deadline having passed does not make it
+// a timeout.
+func TestRetryLocalDialKeepsUnrelatedErrorAtDeadline(t *testing.T) {
+ for _, cause := range []error{unixdial.ErrPeerMismatch, unixdial.ErrControlEndpoint, errors.New("peer mismatch")} {
+ start := time.Now()
+ _, err := retryLocalDial(context.Background(), start.Add(150*time.Millisecond),
+ func(actx context.Context) (net.Conn, error) {
+ <-actx.Done()
+ return nil, fmt.Errorf("dial: %w", cause)
+ })
+ if !errors.Is(err, cause) {
+ t.Fatalf("cause %v: err = %v, want the cause back", cause, err)
+ }
+ if errors.Is(err, errHoldExpired) || errors.Is(err, context.DeadlineExceeded) {
+ t.Fatalf("cause %v: err = %v, an unrelated error is not a hold timeout", cause, err)
+ }
+ }
+}
+
+// The deadline errors a real dial returns when its context ends it all
+// count as the deadline talking.
+func TestCutByDeadlineClassifiesDialErrors(t *testing.T) {
+ timeoutOp := &net.OpError{Op: "dial", Net: "unix", Err: os.ErrDeadlineExceeded}
+ for name, c := range map[string]struct {
+ cut bool
+ err error
+ want bool
+ }{
+ "context deadline": {true, context.DeadlineExceeded, true},
+ "wrapped canceled": {true, &net.OpError{Op: "dial", Err: context.Canceled}, true},
+ "os deadline": {true, timeoutOp, true},
+ "not cut": {false, context.DeadlineExceeded, false},
+ "peer mismatch": {true, unixdial.ErrPeerMismatch, false},
+ "wrapped control refusal": {true, fmt.Errorf("x: %w", unixdial.ErrControlEndpoint), false},
+ } {
+ if got := cutByDeadline(c.cut, c.err); got != c.want {
+ t.Errorf("%s: cutByDeadline = %v, want %v", name, got, c.want)
+ }
+ }
+}
+
func TestRetryLocalDialNonRetryableFailsAtOnce(t *testing.T) {
var calls int
boom := errors.New("boom")
diff --git a/internal/provision/testdata/plan14-root-reads-edge-roll-blip.tsv b/internal/provision/testdata/plan14-root-reads-edge-roll-blip.tsv
index d6ad432fd..d08ddf8f6 100644
--- a/internal/provision/testdata/plan14-root-reads-edge-roll-blip.tsv
+++ b/internal/provision/testdata/plan14-root-reads-edge-roll-blip.tsv
@@ -4,4 +4,4 @@
@legacy 528f68a4cbb7495c8fd1f8466db17b41c33a36bfcaaff49ae8ea8306d88004fa internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 bd0fe0c5d01e83e4de5bb755d791cf9e53168be3083424df147c879004c784bf
internal/edge/edge.go Edge.Reload legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-design-edge-rate-limit-358;basis=each route's upstream entry gains rate: e.parseRateSettings(t), the row's rate_limit column parsed once per reload; the one added site is that whole:Route pass of t (parseRateSettings is a new unit, classified in the decisions overlay); no other read added;rev3=census-ruling-certwarm-wake;basis=the single reload hook call becomes runReloadHooks(), which runs every registered hook in order (#386); no read added, same 57 sites (56 before #358 landed on main);rev3=census-ruling-edge-asset-cache-3;basis=each tenant reverse proxy built in the switch (the tunnel, fleet, socket and TCP arms, every *httputil.ReverseProxy) is installed behind assetScrubbedProxy, which hands the proxy an assetInformationalScrub writer so an app's 1xx (103) loses the asset cache's reserved headers (X-Carlos-Asset-Fill, -Fill-Ack, -Expires, Carlos-Cache) on every local path, as the backhaul already does (final review F6); a type check of the proxy it just built and a wrapper around it; static and status handlers untouched; read sites unchanged (57), offsets moved; no read added;rev3=census-ruling-alias-wake-338;basis=#338 follow-up: after the path fold, a resolved platform alias takes its source's own upstream entry (same proxy, route, hibernating: the existing activator wake, lease and fence), keeping its own prefix map (none for a minted apex) and never inheriting the source's (Astra r2 P1); a refused alias, or one whose source has no entry, is dropped from the map (not served, not Allowed); the attached-hostname fold clears platformAlias;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3 Task 5: the activator-managed test (generation proxy, hib, no-activator 404) is Route.ActivatorOwned instead of Kind and Hibernate inline, so a resident rootfs instance goes through the activator; binary rows unchanged;rev3=census-ruling-edge-roll-blip;basis=the tcpProxy and multiProxy calls pass e.hold (the per-Edge localHold set once in newEdge): a loopback TCP upstream that refuses is redialled for up to 13 s and a probed route with a local upstream waits for prober readmission instead of answering 502/503 (#434 part B); edge-side dial policy only, no read added, same 52 sites registry:Account@20309,registry:Alias@18478,registry:Alias@18565,registry:Alias@18801,registry:FleetBox@5526,registry:Health@7671,registry:Health@7797,registry:Host@13212,registry:Host@15119,registry:Host@15427,registry:Host@15454,registry:Host@16255,registry:Host@16521,registry:Host@18604,registry:Host@6080,registry:Host@8280,registry:Host@8375,registry:Host@8663,registry:Host@8689,registry:Host@8741,registry:Kind@11548,registry:Kind@11570,registry:Kind@8837,registry:Kind@8897,registry:Name@20299,registry:Prefix@16496,registry:Region@2252,registry:Socket@15435,registry:Socket@5633,registry:Socket@6144,registry:Status@1835,registry:Target@16508,registry:Tunnel@4574,registry:Tunnel@4630,registry:Version@11529,registry:Version@11631,whole:Fleet@20249,whole:Fleet@20278,whole:Route@130,whole:Route@15487,whole:Route@15494,whole:Route@15590,whole:Route@17399,whole:Route@4692,whole:Route@5590,whole:Route@6200,whole:Route@648,whole:Route@8814,whole:Route@8887,whole:Route@8947,whole:RouteAlias@18449,whole:RoutePath@16233 d8c48c887841a643a6d9db6d58c8b7213c8024e8b2f6c6c25f355db03413a9f8
internal/edge/edge.go RunWithActivatorReady legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-certwarm-wake;basis=registers the cert warm's nudge on OnReload and on the home map's new served-hosts wake (#386); nudge only sends on a buffered channel; no read added, same 5 sites;rev3=census-ruling-edge-roll-blip;basis=the :80/:443 (and dev) listeners are bound on the calling goroutine with net.Listen via listen()/listenAddr (same empty-address defaults as ListenAndServe) before the serve goroutines, which now call Serve/ServeTLS on them, and one log line names the bound addresses; no read added, same 5 sites data-literal@129,data-literal@148,data-literal@284,data-literal@417,file:Open@1013 bd0fe0c5d01e83e4de5bb755d791cf9e53168be3083424df147c879004c784bf
-@coverage internal/edge c49b61e4d73f72240764abffd6e6a72ec67d87686d64163bbb094b374742b008
+@coverage internal/edge 2704220c7fb97c7f3c80af6324edff5981943a0a0885c8f56b601b047f7db979