le13ure on X: after the LAN address of a magpie used as a Remote magpie provider changed and the user edited it in the provider, requests already under way kept retrying the old address instead of switching. Each request held the Provider it started with, and its retries (the same-one pauses up to 8s, a group's and a provider's patience up to 30s) asked that copy's address again. The look for a moved magpie (SeekMoved, v0.1.3177) ran at most once a minute, so other requests within the minute got nothing from it and kept the stale address. And a dial to a LAN address no one holds now waited on the OS (~75s macOS, ~127s Linux) per try. - provider.Readdressed: a Remote magpie copy moved onto the address saved now. The gateway's try loop asks it before each try; SeekMoved returns it when another look or the user saved one. - provider.Edited: store() signals every save; a pause between tries (pauseAlive, new pauseUntilReaddressed) ends when the waiting Remote magpie's address changed, so the next try goes at once. - netproxy: Dispatch's transports give a dial to a private or link-local IP literal 5s (lanDialCap). Names, public, CGNAT/Tailscale untouched. - docs: providers-accounts "A remote magpie that moved". Run (mote, nogui, at this tree): go test ./internal/netproxy ./internal/provider ./internal/gateway -run 'TestLANDial|TestLAN|TestDispatch|TestRemoteMagpie|TestPauseEnds|Patience|Replan' ok; go vet of the three packages for darwin, linux and windows ok; gofmt -l clean. mote was at load ~28 over its 18 cores (mica's disk is full), so timings ran slow. Broken by hand, each red: lanDialCap off (TestLANDialGivesUp, "no deadline"); Readdressed out of SeekMoved (TestRemoteMagpieSavedElsewhereIsTaken); the loop-head Readdressed off (TestRemoteMagpieRetryGoesToTheSavedAddress, 503 from the old address); the Edited wake out of pauseUntilReaddressed (TestPauseEndsWhenReaddressed, the pause ran its full 30s). Not tried: a real two-computer LAN move; the full suite before the push (started after it).
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package netproxy
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A connection to an address on the user's own network that nobody holds
|
|
// any more (le13ure on X: a Remote magpie whose computer was given
|
|
// another address) is given up on after lanDial, not after the system's
|
|
// minute or two; a name, a public address and Tailscale's are left to
|
|
// the request's own context.
|
|
func TestLANDialGivesUp(t *testing.T) {
|
|
old := lanDial
|
|
lanDial = 20 * time.Millisecond
|
|
t.Cleanup(func() { lanDial = old })
|
|
tr := &http.Transport{DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
|
|
if _, ok := ctx.Deadline(); !ok {
|
|
return nil, errors.New("no deadline: " + addr)
|
|
}
|
|
<-ctx.Done() // an address that never answers
|
|
return nil, ctx.Err()
|
|
}}
|
|
lanDialCap(tr)
|
|
for _, addr := range []string{"192.168.1.20:3425", "10.0.0.5:3425", "172.16.3.4:3425", "169.254.1.1:3425"} {
|
|
if _, err := tr.DialContext(context.Background(), "tcp", addr); !errors.Is(err, context.DeadlineExceeded) {
|
|
t.Errorf("%s: %v, want given up on", addr, err)
|
|
}
|
|
}
|
|
for _, addr := range []string{"a-pc.local:3425", "8.8.8.8:443", "100.100.1.2:3425", "api.example.com:443"} {
|
|
if _, err := tr.DialContext(context.Background(), "tcp", addr); err == nil || errors.Is(err, context.DeadlineExceeded) {
|
|
t.Errorf("%s: %v, want left to the request's context", addr, err)
|
|
}
|
|
}
|
|
}
|