Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/ServerManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,31 @@ public function playwright(): PlaywrightServer
return AlreadyStartedPlaywrightServer::fromPersisted();
}

$port = Port::find();
$host = Playwright::host() ?? self::DEFAULT_HOST;
// Allocating the port and persisting the description belong INSIDE the
// guard, with the creation they describe. `??=` already makes the server
// a one-off, but both lines around it ran on every call: the 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 the workers connect
// to a dead port.
if (! $this->playwright instanceof PlaywrightServer) {
$port = Port::find();
$host = Playwright::host() ?? self::DEFAULT_HOST;

$this->playwright ??= PlaywrightNpmServer::create(
PackageJsonDirectory::find(),
'.'.DIRECTORY_SEPARATOR.'node_modules'.DIRECTORY_SEPARATOR.'.bin'.DIRECTORY_SEPARATOR.'playwright run-server --host %s --port %d --mode launchServer',
$host,
$port,
'Listening on',
);
$this->playwright = PlaywrightNpmServer::create(
PackageJsonDirectory::find(),
'.'.DIRECTORY_SEPARATOR.'node_modules'.DIRECTORY_SEPARATOR.'.bin'.DIRECTORY_SEPARATOR.'playwright run-server --host %s --port %d --mode launchServer',
$host,
$port,
'Listening on',
);

AlreadyStartedPlaywrightServer::persist(
$host,
$port,
);
AlreadyStartedPlaywrightServer::persist(
$host,
$port,
);
}

return $this->playwright;
}
Expand Down