| index cf82a9793..6dfe95d79 100644 |
| --- a/internal/host/unitsettle.go |
| +++ b/internal/host/unitsettle.go |
| @@ -295,16 +295,9 @@ func unitSettleTimeout(getenv func(string) string) time.Duration { |
| // routeReady is the readiness check for rt's effective upstream (spec §2.4): |
| // Socket wins over Addr. With a configured probe it is an HTTP GET; without |
| // one, a connect. nil when the route has no upstream: settle then requires |
| -// the unit to stay active for its Hold. |
| +// the unit to stay active for its Hold. Both dial through upstreamguard |
| +// (readyConnect, readyProbe). |
| func routeReady(rt registry.Route, timeout time.Duration) func() error { |
| - return routeReadyVia(net.Dialer{}, rt, timeout) |
| -} |
| - |
| -// routeReadyVia is routeReady dialing with base (a test sets its Resolver) |
| -// behind upstreamguard: a TCP upstream is route-supplied, so both the |
| -// connect and the probe refuse a link-local or IMDS destination after |
| -// resolution and before connect. A unix socket path passes the guard. |
| -func routeReadyVia(base net.Dialer, rt registry.Route, timeout time.Duration) func() error { |
| network, address := "unix", rt.Socket |
| if address == "" { |
| network, address = "tcp", rt.Addr |
| @@ -313,16 +306,7 @@ func routeReadyVia(base net.Dialer, rt registry.Route, timeout time.Duration) fu |
| return nil |
| } |
| if rt.Health == "" { |
| - d := base |
| - d.Timeout = timeout |
| - dialer := upstreamguard.Dialer(d) |
| - return func() error { |
| - c, err := dialer.Dial(network, address) |
| - if err != nil { |
| - return fmt.Errorf("connect %s: %w", address, err) |
| - } |
| - return c.Close() |
| - } |
| + return readyConnect(net.Dialer{}, network, address, timeout) |
| } |
| var h provision.Health |
| if err := json.Unmarshal([]byte(rt.Health), &h); err != nil { |
| @@ -333,6 +317,27 @@ func routeReadyVia(base net.Dialer, rt registry.Route, timeout time.Duration) fu |
| if hostHdr == "" { |
| hostHdr = rt.Host |
| } |
| + return readyProbe(net.Dialer{}, network, address, h, hostHdr, timeout) |
| +} |
| + |
| +// readyConnect is routeReady's connect check, dialing with base (a test sets |
| +// its Resolver) behind upstreamguard: a TCP upstream is route-supplied, so a |
| +// link-local or IMDS destination is refused after resolution and before |
| +// connect. A unix socket path passes the guard. |
| +func readyConnect(base net.Dialer, network, address string, timeout time.Duration) func() error { |
| + base.Timeout = timeout |
| + dialer := upstreamguard.Dialer(base) |
| + return func() error { |
| + c, err := dialer.Dial(network, address) |
| + if err != nil { |
| + return fmt.Errorf("connect %s: %w", address, err) |
| + } |
| + return c.Close() |
| + } |
| +} |
| + |
| +// readyProbe is routeReady's HTTP probe, dialing as readyConnect does. |
| +func readyProbe(base net.Dialer, network, address string, h provision.Health, hostHdr string, timeout time.Duration) func() error { |
| dialer := upstreamguard.Dialer(base) |
| client := &http.Client{Timeout: timeout, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }, Transport: &http.Transport{ |
| DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { |