From ae04a6f56fc821a83148134e0133d9d34b182e10 Mon Sep 17 00:00:00 2001 From: Chris Speciale Date: Fri, 13 Nov 2026 01:04:38 -0500 Subject: [PATCH] Give PollRegistrations' checks ten seconds for loopback to deliver PollRegistrations failed now and then on macOS arm64 runners, a socket that had been sent bytes not reported readable within the second each check waited (libhxcpp #431). A traced loop of 400 runs on a runner failed 3 times this way and once with datagrams, and showed the kqueue backend was right: for the whole wait the client's FIONREAD was 0 and the server's write filter reported the 5 bytes still in its send buffer, so loopback had not delivered them. They arrived later, as the blocking read after the checks got them. A check now polls until its result matches or ten seconds pass, so it stops as soon as it matches and only a failing check waits the whole time. The library is unchanged. --- test/regression/PollRegistrations/Main.hx | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/regression/PollRegistrations/Main.hx b/test/regression/PollRegistrations/Main.hx index 73e3a3eec..ea5fbcf33 100644 --- a/test/regression/PollRegistrations/Main.hx +++ b/test/regression/PollRegistrations/Main.hx @@ -37,16 +37,21 @@ class Main { return "[" + shown.join(",") + "]"; } - // Polls until the expected indexes are ready, as a datagram can take a - // moment to arrive: loopback delivers at once, but not before send returns + // Polls until the expected indexes are ready, as bytes can take a moment + // to arrive: loopback usually delivers at once, but not before send + // returns, and a macOS runner has held a datagram or a TCP segment back + // for more than two seconds, the bytes still in the sender's buffer and + // none in the receiver's (openfl/libhxcpp#431). A check that matches stops + // at once, so only a failing one waits the whole time. + static inline var patience = 10.0; + static function events(poll:Poll, expectRead:String, expectWrite = "[]"):String { var got = ""; - for (attempt in 0...50) { + var deadline = haxe.Timer.stamp() + patience; + do { poll.events(0.02); got = indexes(poll.readIndexes) + " " + indexes(poll.writeIndexes); - if (got == '$expectRead $expectWrite') - break; - } + } while (got != '$expectRead $expectWrite' && haxe.Timer.stamp() < deadline); return got; } @@ -142,11 +147,10 @@ class Main { // Poll.poll prepares and waits in one call ping(sockets[7]); var ready = []; - for (attempt in 0...50) { + var deadline = haxe.Timer.stamp() + patience; + do { ready = poll.poll(cast sockets, 0.02); - if (ready.length > 0) - break; - } + } while (ready.length == 0 && haxe.Timer.stamp() < deadline); Sys.println('poll: ${ready.length == 1 && ready[0] == cast sockets[7]}'); drain(sockets[7]);