Repository navigation
Conversation
The test server picked a random port in 9000-9999 and relied on WebSocketServer.start to report a taken port, but start returns before the NWListener binds, so the retry loop never retried. Listeners from earlier tests are never stopped (Starscream has no API for it), so a collision sent the client to a dead listener and the test timed out. Ask the OS for a free port instead, wait for the server to register the connection before broadcasting, and keep the server's client list on the main thread.
Collaborator
Generated by 🚫 Danger |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 34704 | |
| Version | PR #26088 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 26eeaea | |
| Installation URL | 1ls4su5oia43o |
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 34704 | |
| Version | PR #26088 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 26eeaea | |
| Installation URL | 0g2g8tkomip5g |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Fixes
PinghubWebSocketTests.testReceiveManyMessage(62% reliable over the last 7 days in Test Engine, labeledflaky). The same bug affects every test in the class;testReceiveManyMessageis just the one that loses most often on CI.Root Cause
PinghubServerpicked a random port in9000...9999and retried up to 5 times ifWebSocketServer.startreturned an error. But Starscream'sstartcreates anNWListenerand returnsnilright away — the bind happens asynchronously — so a taken port is never reported and the retry loop never retries:The port is usually taken by a listener from an earlier test.
PinghubServernever stops its listener (Starscream 4.0.8 has no API for it), so listeners pile up for the life of the test process. When a new server lands on one of their ports, the client connects to the stale listener, the connection gets reset, and the test waits out its 20s timeout.Reproduced locally by running
PinghubWebSocketTests30× in one process: 11/150 executions failed, and 22 of the 150 servers hitAddress already in use.Separately,
connect()only waited for the client to see the upgrade response. The server appends the connection toclientsjust after sending that response, on its own queue, so a broadcast could in principle race it (andclientswas read and written from two threads).Fix
unusedPort()binds a dual-stack socket to port 0, reads the assigned port withgetsockname, and releases it for the server. Leaked listeners still hold their ports, so the OS won't hand those out.connect(). The server fulfills a "registered" expectation once it has the connection, sobroadcastnever runs against an emptyclientslist.clientson the main thread. Server events hop to main before touching the list.Test-only;
PinghubClientis unchanged.Test plan
PinghubWebSocketTests× 100 iterations in one process (Xcode 27.0, iOS 27.0 simulator) — 500/500 passed, 0Address already in use, 2.8s total (vs 190s with the timeouts)