Skip to content

Commit f5a9ea3

Browse files
Merge branch '4.4' into 5.1
* 4.4: Disable the PhpUnit bridge when testing it [PropertyInfo] Support for the mixed type. Don't unset the inflate resource on close as it might still be needed [HttpClient] Fix CurlHttpClient memory leak [Form] Add Bosnian (bs) validators translation [Form] Add missing Serbian (latn & cyrl) validators translation [Cache] skip igbinary < 3.1.6 [Ldap] Bypass the use of `ldap_control_paged_result` on PHP >= 7.3 [Form] [Validator] added pt_BR translations Estonian update [PhpUnitBridge] fix running parallel tests with phpunit 9 [VarDumper] fix truncating big arrays
2 parents b78a8f5 + 0af2c21 commit f5a9ea3

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

Response/CurlResponse.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\HttpClient\Exception\TransportException;
1818
use Symfony\Component\HttpClient\Internal\ClientState;
1919
use Symfony\Component\HttpClient\Internal\CurlClientState;
20-
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
2120
use Symfony\Contracts\HttpClient\ResponseInterface;
2221

2322
/**
@@ -205,14 +204,9 @@ public function __destruct()
205204
return; // Unused pushed response
206205
}
207206

208-
$e = null;
209207
$this->doDestruct();
210-
} catch (HttpExceptionInterface $e) {
211-
throw $e;
212208
} finally {
213-
if ($e ?? false) {
214-
throw $e;
215-
}
209+
$multi = clone $this->multi;
216210

217211
$this->close();
218212

@@ -221,6 +215,8 @@ public function __destruct()
221215
$this->multi->dnsCache->evictions = $this->multi->dnsCache->evictions ?: $this->multi->dnsCache->removals;
222216
$this->multi->dnsCache->removals = $this->multi->dnsCache->hostnames = [];
223217
}
218+
219+
$this->multi = $multi;
224220
}
225221
}
226222

@@ -229,7 +225,6 @@ public function __destruct()
229225
*/
230226
private function close(): void
231227
{
232-
$this->inflate = null;
233228
unset($this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
234229
curl_setopt($this->handle, \CURLOPT_PRIVATE, '_0');
235230

Response/NativeResponse.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\HttpClient\Exception\TransportException;
1717
use Symfony\Component\HttpClient\Internal\ClientState;
1818
use Symfony\Component\HttpClient\Internal\NativeClientState;
19-
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
2019
use Symfony\Contracts\HttpClient\ResponseInterface;
2120

2221
/**
@@ -87,14 +86,9 @@ public function getInfo(string $type = null)
8786
public function __destruct()
8887
{
8988
try {
90-
$e = null;
9189
$this->doDestruct();
92-
} catch (HttpExceptionInterface $e) {
93-
throw $e;
9490
} finally {
95-
if ($e ?? false) {
96-
throw $e;
97-
}
91+
$multi = clone $this->multi;
9892

9993
$this->close();
10094

@@ -103,6 +97,8 @@ public function __destruct()
10397
$this->multi->responseCount = 0;
10498
$this->multi->dnsCache = [];
10599
}
100+
101+
$this->multi = $multi;
106102
}
107103
}
108104

@@ -197,7 +193,7 @@ private function open(): void
197193
private function close(): void
198194
{
199195
unset($this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
200-
$this->handle = $this->buffer = $this->inflate = $this->onProgress = null;
196+
$this->handle = $this->buffer = $this->onProgress = null;
201197
}
202198

203199
/**

Tests/HttpClientTestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
namespace Symfony\Component\HttpClient\Tests;
1313

1414
use Symfony\Component\HttpClient\Exception\ClientException;
15+
use Symfony\Component\HttpClient\Internal\ClientState;
1516
use Symfony\Component\HttpClient\Response\StreamWrapper;
1617
use Symfony\Component\Process\Exception\ProcessFailedException;
1718
use Symfony\Component\Process\Process;
19+
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
1820
use Symfony\Contracts\HttpClient\HttpClientInterface;
1921
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
2022

@@ -246,4 +248,26 @@ private static function startVulcain(HttpClientInterface $client)
246248

247249
self::$vulcainStarted = true;
248250
}
251+
252+
public function testHandleIsRemovedOnException()
253+
{
254+
$client = $this->getHttpClient(__FUNCTION__);
255+
256+
try {
257+
$client->request('GET', 'http://localhost:8057/304');
258+
$this->fail(RedirectionExceptionInterface::class.' expected');
259+
} catch (RedirectionExceptionInterface $e) {
260+
// The response content-type mustn't be json as that calls getContent
261+
// @see src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php:58
262+
$this->assertStringNotContainsString('json', $e->getResponse()->getHeaders(false)['content-type'][0] ?? '');
263+
264+
$r = new \ReflectionProperty($client, 'multi');
265+
$r->setAccessible(true);
266+
/** @var ClientState $clientState */
267+
$clientState = $r->getValue($client);
268+
269+
$this->assertCount(0, $clientState->handlesActivity);
270+
$this->assertCount(0, $clientState->openHandles);
271+
}
272+
}
249273
}

Tests/MockHttpClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ protected function getHttpClient(string $testCase): HttpClientInterface
240240
$this->markTestSkipped("MockHttpClient doesn't timeout on destruct");
241241
break;
242242

243+
case 'testHandleIsRemovedOnException':
244+
$this->markTestSkipped("MockHttpClient doesn't cache handles");
245+
break;
246+
243247
case 'testGetRequest':
244248
array_unshift($headers, 'HTTP/1.1 200 OK');
245249
$responses[] = new MockResponse($body, ['response_headers' => $headers]);

0 commit comments

Comments
 (0)