From d7b32f75d341c28ab2ebcad590d937151da03eeb Mon Sep 17 00:00:00 2001 From: Bart Van Bos Date: Sat, 14 Nov 2026 10:21:56 +0100 Subject: [PATCH] test(discover): repeat the flood's replies until discover is done TestHostileDiscoverFlood sent 500 junk datagrams and then the replies of 40 devices once. The junk is several times Linux's default UDP receive buffer (about 208 KiB): when the command's reader runs late on a busy runner, the kernel drops everything after the junk, the replies included, and discover found 0 of 10 (ethernetipctl#26, ubuntu-24.04, Go 1.26 job). A probe with that buffer size and a reader 50 ms late read 304 junk datagrams and 0 of 200 replies. The devices now repeat their replies every 20 ms until the command returns; the flood, the --max-devices limit and the duration bound are unchanged. Fixes #26 Co-Authored-By: Claude Opus 5.5 --- cmd/hostile_device_test.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/hostile_device_test.go b/cmd/hostile_device_test.go index 8ebfb9a..7e1b633 100644 --- a/cmd/hostile_device_test.go +++ b/cmd/hostile_device_test.go @@ -491,7 +491,9 @@ func TestHostileDiscoverFlood(t *testing.T) { } }) rnd := rand.New(rand.NewPCG(5, 6)) - done := make(chan struct{}) + done, stop := make(chan struct{}), make(chan struct{}) + stopDevices := sync.OnceFunc(func() { close(stop) }) + t.Cleanup(stopDevices) go func() { defer close(done) buf := make([]byte, 1500) @@ -520,14 +522,27 @@ func TestHostileDiscoverFlood(t *testing.T) { } good := append([]byte(nil), template...) copy(good[12:20], ctx) - for _, s := range socks { - for range 5 { // duplicates of each device - _, _ = s.WriteTo(good, from) + // The flood can fill the command's receive buffer (Linux's default + // is about 208 KiB): until the command has read the junk, the kernel + // drops what follows, and a command scheduled late on a busy + // machine missed every reply (ethernetipctl#26). The devices repeat + // their replies, more duplicates, until the command is done. + for { + for _, s := range socks { + for range 5 { // duplicates of each device + _, _ = s.WriteTo(good, from) + } + } + select { + case <-stop: + return + case <-time.After(20 * time.Millisecond): } } }() start := time.Now() r := run(t, "discover", "--address", dev.LocalAddr().String(), "--wait", "2s", "--max-devices", "10", "--format", "json").want(t, 0) + stopDevices() m := r.json(t) if m["found"] != 10.0 { t.Errorf("found %v, want 10 (--max-devices)", m["found"])