Skip to content

Separate setting of SO_KEEPALIVE in FPM tests #12640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions sapi/fpm/tests/fcgi.inc
Original file line number Diff line number Diff line change
Expand Up @@ -476,16 +476,16 @@ class Client
}

/**
* Define whether or not the FastCGI application should keep the connection
* alive at the end of a request
* Define whether the FastCGI application should keep the connection
* alive at the end of a request and additionally set SO_KEEPALIVE or not.
*
* @param bool $b true if the connection should stay alive, false otherwise
* @param bool $connKeepAlive true if the connection should stay alive, false otherwise
* @param bool $socketKeepAlive true if the socket SO_KEEPALIVE should be set, false otherwise
*/
public function setKeepAlive($b)
public function setKeepAlive(bool $connKeepAlive, bool $socketKeepAlive)
{
$value = (bool) $b;
$this->_keepAlive = $value;
$this->transport->setKeepAlive($value);
$this->_keepAlive = $connKeepAlive;
$this->transport->setKeepAlive($socketKeepAlive);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion sapi/fpm/tests/proc-idle-timeout.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ EOT;
$tester = new FPM\Tester($cfg, $code);
$tester->start();
$tester->expectLogStartNotices();
$tester->multiRequest(2, null, null, null, false, 7000);
$tester->multiRequest(2, readTimeout: 7000);
$tester->status([
'total processes' => 2,
]);
Expand Down
65 changes: 41 additions & 24 deletions sapi/fpm/tests/tester.inc
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ class Tester
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $connKeepAlive
* @param bool $socketKeepAlive
* @param string|null $scriptFilename = null
* @param string|null $scriptName = null
* @param string|array|null $stdin = null
Expand All @@ -828,6 +829,7 @@ class Tester
string $successMessage = null,
string $errorMessage = null,
bool $connKeepAlive = false,
bool $socketKeepAlive = false,
string $scriptFilename = null,
string $scriptName = null,
string|array $stdin = null,
Expand All @@ -848,7 +850,8 @@ class Tester

try {
$this->response = new Response(
$this->getClient($address, $connKeepAlive)->request_data($params, $stdin, $readLimit, $writeDelay)
$this->getClient($address, $connKeepAlive, $socketKeepAlive)
->request_data($params, $stdin, $readLimit, $writeDelay)
);
if ($expectError) {
$this->error('Expected request error but the request was successful');
Expand Down Expand Up @@ -879,6 +882,7 @@ class Tester
* @param string|null $address
* @param string|null $successMessage
* @param string|null $errorMessage
* @param bool $socketKeepAlive
* @param bool $connKeepAlive
* @param int $readTimeout
* @param int $writeDelay
Expand All @@ -892,6 +896,7 @@ class Tester
string $successMessage = null,
string $errorMessage = null,
bool $connKeepAlive = false,
bool $socketKeepAlive = false,
int $readTimeout = 0,
int $writeDelay = 0,
) {
Expand All @@ -904,23 +909,26 @@ class Tester
}

try {
$connections = array_map(function ($requestData) use ($address, $connKeepAlive, $writeDelay) {
$client = $this->getClient($address, $connKeepAlive);
$params = $this->getRequestParams(
$requestData['query'] ?? '',
$requestData['headers'] ?? [],
$requestData['uri'] ?? null
);

if (isset($requestData['delay'])) {
usleep($requestData['delay']);
}
$connections = array_map(
function ($requestData) use ($address, $connKeepAlive, $socketKeepAlive, $writeDelay) {
$client = $this->getClient($address, $connKeepAlive, $socketKeepAlive);
$params = $this->getRequestParams(
$requestData['query'] ?? '',
$requestData['headers'] ?? [],
$requestData['uri'] ?? null
);

if (isset($requestData['delay'])) {
usleep($requestData['delay']);
}

return [
'client' => $client,
'requestId' => $client->async_request($params, false, $writeDelay),
];
}, $requests);
return [
'client' => $client,
'requestId' => $client->async_request($params, false, $writeDelay),
];
},
$requests
);

$responses = array_map(function ($conn) use ($readTimeout) {
$response = new Response($conn['client']->wait_for_response_data($conn['requestId'], $readTimeout));
Expand Down Expand Up @@ -949,13 +957,15 @@ class Tester
*
* @param string|null $address
* @param bool $connKeepAlive
* @param bool $socketKeepAlive
*
* @return ValuesResponse
* @throws \Exception
*/
public function requestValues(
string $address = null,
bool $connKeepAlive = false
bool $connKeepAlive = false,
bool $socketKeepAlive = false
): ValuesResponse {
if ($this->hasError()) {
return new Response(null, true);
Expand All @@ -979,13 +989,17 @@ class Tester
/**
* Get client.
*
* @param string $address
* @param bool $keepAlive
* @param string|null $address
* @param bool $connKeepAlive
* @param bool $socketKeepAlive
*
* @return Client
*/
private function getClient(string $address = null, bool $keepAlive = false): Client
{
private function getClient(
string $address = null,
bool $connKeepAlive = false,
bool $socketKeepAlive = false
): Client {
$address = $address ? $this->processTemplate($address) : $this->getAddr();
if ($address[0] === '/') { // uds
$host = 'unix://' . $address;
Expand All @@ -1005,13 +1019,16 @@ class Tester
$port = $addressParts[1] ?? $this->getPort();
}

if ( ! $keepAlive) {
if ($socketKeepAlive) {
$connKeepAlive = true;
}
if ( ! $connKeepAlive) {
return new Client($host, $port, $this->createTransport());
}

if ( ! isset($this->clients[$host][$port])) {
$client = new Client($host, $port, $this->createTransport());
$client->setKeepAlive(true);
$client->setKeepAlive($connKeepAlive, $socketKeepAlive);
$this->clients[$host][$port] = $client;
}

Expand Down