Persist the port of the server that was actually started - #246
Open
yeapea wants to merge 1 commit into
Open
Conversation
`??=` already makes the Playwright server a one-off, but the two lines around it ran on every call to `playwright()`. So a second call allocated a fresh port that nothing was listening on, and then persisted that port as the description of the server that IS running. Every later `visit()` reads that description, so workers connect to a dead port. Moving the port allocation and the persist inside the guard keeps them with the creation they describe.
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.
The defect
ServerManager::playwright()creates the Playwright server once —??=sees to that — but the two lines around the assignment run on every call:The port lives on the server instance as a readonly property, so the server keeps the port it was created with. But the second call runs
Port::find()again — which by definition returns a port nothing is listening on, since the running server's port is now taken — and persists that as the description of the server.The server is fine. The record of where to reach it is not, and that record is what
AlreadyStartedPlaywrightServer::fromPersisted()hands to every parallel worker.The measurement
Two calls to
playwright()in one process,start()ed in between so the server is genuinely listening, reading.temp/playwright-server.jsonafter each:Before
After
The same server object is returned either way — only the persisted description moves, onto a port that refuses connections.
The fix
Move the port allocation and the
persist()inside the guard, so they stay with the creation they describe:Nothing changes on the first call. On every later call the method now returns the same server and leaves its description alone.
composer lint(rector + pint) is clean on the changed file.A related finding, deliberately not in this PR
While tracking this down I ran into a second issue in the same area: the persisted state file has no run identity, so two concurrent runs on one machine share it — the second overwrites the first's description, and whichever finishes first removes the file out from under the other via
markAsStopped().I left it out because fixing it properly means deciding how a run is identified and what happens to a stale file, and those are design calls that belong to you rather than to a drive-by PR. Happy to open it separately with a measurement if the shape you'd want is clear — or to just leave it here as a report.