Skip to content

[HttpClient] CurlHttpClient keep reference to resources passed by form data #60506

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

Open
alex-dev opened this issue May 21, 2025 · 0 comments
Open

Comments

@alex-dev
Copy link
Contributor

alex-dev commented May 21, 2025

Symfony version(s) affected

Confirmed for 6.4

Description

When using form data and resources, CurlHttpClient leaks the resource. It is likely kept alive by a CurlHandle at that point.

How to reproduce

<?php

use Symfony\Component\HttpClient\CurlHttpClient;

require_once __DIR__ . '/vendor/autoload.php';

$client = new CurlHttpClient();
$data = fopen('php://memory', 'r+');
$canary = fopen('php://memory', 'r+');
fwrite($data, random_bytes(1024));
fwrite($canary, random_bytes(1024));
rewind($data);
rewind($canary);

$client->request('POST', 'http://127.0.0.1:8061/imports', ['body' => ['data' => $data]]);
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

unset($data);
unset($canary);
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

$client->reset();
dump(array_map(stream_get_meta_data(...), get_resources('stream')));

Each dump return the resource held by $data. The resource held by $canary is only returned by the first dump.
Do note that passing the resource as body (e.g. ['body' => $data]) works as expected.

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

No branches or pull requests

2 participants