Release 3.8.0.3: fix Hy2/AWG UDP ping false negatives.
This commit is contained in:
@@ -2,7 +2,7 @@ package netcheck
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func TestFriendlyDialError(t *testing.T) {
|
||||
err := &netError{s: "dial tcp 1.2.3.4:22514: connectex: No connection could be made because the target machine actively refused it."}
|
||||
got := friendlyDialError(err, true)
|
||||
if !strings.Contains(got, "UDP") {
|
||||
if got == "" || got == err.Error() {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
@@ -31,3 +31,67 @@ func TestPingProfileEmpty(t *testing.T) {
|
||||
t.Fatalf("%+v", r)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbeUDPSoftOKWhenSilent(t *testing.T) {
|
||||
pc, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pc.Close()
|
||||
// Intentionally do not Read — mimics Hy2/AWG ignoring garbage probes.
|
||||
_, port, err := net.SplitHostPort(pc.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
start := time.Now()
|
||||
rtt, err := probeUDP(ctx, "127.0.0.1", port)
|
||||
if err != nil {
|
||||
t.Fatalf("expected soft-ok, got err=%v", err)
|
||||
}
|
||||
if rtt <= 0 {
|
||||
t.Fatalf("rtt=%v", rtt)
|
||||
}
|
||||
if time.Since(start) > 900*time.Millisecond {
|
||||
t.Fatalf("soft-ok waited too long: %v (should not use long timeout)", time.Since(start))
|
||||
}
|
||||
|
||||
res := PingProfile(ctx, "silent", config.ProtocolHysteria2, "hysteria2://x@127.0.0.1:"+port+"/")
|
||||
if !res.OK {
|
||||
t.Fatalf("PingProfile soft-ok failed: %+v", res)
|
||||
}
|
||||
if res.Ms < 1 {
|
||||
t.Fatalf("ms=%d", res.Ms)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProbeUDPReplyOK(t *testing.T) {
|
||||
pc, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pc.Close()
|
||||
go func() {
|
||||
buf := make([]byte, 64)
|
||||
n, addr, err := pc.ReadFrom(buf)
|
||||
if err != nil || n == 0 {
|
||||
return
|
||||
}
|
||||
_, _ = pc.WriteTo([]byte{1}, addr)
|
||||
}()
|
||||
_, port, err := net.SplitHostPort(pc.LocalAddr().String())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
rtt, err := probeUDP(ctx, "127.0.0.1", port)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rtt <= 0 {
|
||||
t.Fatalf("rtt=%v", rtt)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user