Skip to content
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

Over file descriptor when not get body for response #368

Open
xpader opened this issue Nov 15, 2024 · 3 comments
Open

Over file descriptor when not get body for response #368

xpader opened this issue Nov 15, 2024 · 3 comments

Comments

@xpader
Copy link
Contributor

xpader commented Nov 15, 2024

Payload will not been destruct from memory when not read body.

while (true) {
    $url = 'Some short url';
    $response = $client->request(new Request($url));
    echo $response->getHeader('Location');
}

You can add a static counter on Payload construct and destruct, will find out.

How is it currently fixed in the own code?

Call $response->getBody()->buffer() or $response->getBody()->close() after read response.

@xpader
Copy link
Contributor Author

xpader commented Nov 15, 2024

May be should use WeakReference in some stream resource, to make it can auto destruct.

@kelunik
Copy link
Member

kelunik commented Nov 19, 2024

I can't reproduce this with your script, same for the counters, seems to work well and the body is properly GCed.

<?php declare(strict_types=1);

use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;

require __DIR__ . '/../.helper/functions.php';

while (true) {
    try {
        // Instantiate the HTTP client
        $client = HttpClientBuilder::buildDefault();

        // Make an asynchronous HTTP request
        $response = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
        $header = $response->getHeader('Location');

        echo memory_get_usage(true) . PHP_EOL;
    } catch (HttpException $error) {
        echo $error;
    }
}

@xpader
Copy link
Contributor Author

xpader commented Nov 20, 2024

Try this, use a single pool instance.

I'm now using php8.1 with ev extension on ubuntu 20.04 amd64.

<?php declare(strict_types=1);

use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;

require __DIR__ . '/../.helper/functions.php';


// Instantiate the HTTP client
$client = HttpClientBuilder::buildDefault();

while (true) {
    try {
        // Make an asynchronous HTTP request
        $response = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
        $header = $response->getHeader('Location');

        echo memory_get_usage(true) . PHP_EOL;
    } catch (HttpException $error) {
        echo $error;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants