Skip to content

Commit afeb1db

Browse files
Merge branch '5.1' into 5.x
* 5.1: 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 Fix no collection in extract default value [PhpUnitBridge] fix running parallel tests with phpunit 9 [VarDumper] fix truncating big arrays
2 parents 0b0cfee + f5a9ea3 commit afeb1db

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-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
/**
@@ -227,14 +226,9 @@ public function __destruct()
227226
return; // Unused pushed response
228227
}
229228

230-
$e = null;
231229
$this->doDestruct();
232-
} catch (HttpExceptionInterface $e) {
233-
throw $e;
234230
} finally {
235-
if ($e ?? false) {
236-
throw $e;
237-
}
231+
$multi = clone $this->multi;
238232

239233
$this->close();
240234

@@ -243,6 +237,8 @@ public function __destruct()
243237
$this->multi->dnsCache->evictions = $this->multi->dnsCache->evictions ?: $this->multi->dnsCache->removals;
244238
$this->multi->dnsCache->removals = $this->multi->dnsCache->hostnames = [];
245239
}
240+
241+
$this->multi = $multi;
246242
}
247243
}
248244

@@ -251,7 +247,6 @@ public function __destruct()
251247
*/
252248
private function close(): void
253249
{
254-
$this->inflate = null;
255250
unset($this->multi->pauseExpiries[$this->id], $this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
256251
curl_setopt($this->handle, \CURLOPT_PRIVATE, '_0');
257252

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
/**
@@ -94,14 +93,9 @@ public function getInfo(string $type = null)
9493
public function __destruct()
9594
{
9695
try {
97-
$e = null;
9896
$this->doDestruct();
99-
} catch (HttpExceptionInterface $e) {
100-
throw $e;
10197
} finally {
102-
if ($e ?? false) {
103-
throw $e;
104-
}
98+
$multi = clone $this->multi;
10599

106100
$this->close();
107101

@@ -110,6 +104,8 @@ public function __destruct()
110104
$this->multi->responseCount = 0;
111105
$this->multi->dnsCache = [];
112106
}
107+
108+
$this->multi = $multi;
113109
}
114110
}
115111

@@ -211,7 +207,7 @@ private function close(): void
211207
unset($this->multi->hosts[$host]);
212208
}
213209
unset($this->multi->openHandles[$this->id], $this->multi->handlesActivity[$this->id]);
214-
$this->handle = $this->buffer = $this->inflate = $this->onProgress = null;
210+
$this->handle = $this->buffer = $this->onProgress = null;
215211
}
216212

217213
/**

Tests/HttpClientTestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
use Symfony\Component\HttpClient\Exception\ClientException;
1515
use Symfony\Component\HttpClient\Exception\TransportException;
16+
use Symfony\Component\HttpClient\Internal\ClientState;
1617
use Symfony\Component\HttpClient\Response\StreamWrapper;
1718
use Symfony\Component\Process\Exception\ProcessFailedException;
1819
use Symfony\Component\Process\Process;
20+
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
1921
use Symfony\Contracts\HttpClient\HttpClientInterface;
2022
use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
2123

@@ -305,4 +307,26 @@ private static function startVulcain(HttpClientInterface $client)
305307

306308
self::$vulcainStarted = true;
307309
}
310+
311+
public function testHandleIsRemovedOnException()
312+
{
313+
$client = $this->getHttpClient(__FUNCTION__);
314+
315+
try {
316+
$client->request('GET', 'http://localhost:8057/304');
317+
$this->fail(RedirectionExceptionInterface::class.' expected');
318+
} catch (RedirectionExceptionInterface $e) {
319+
// The response content-type mustn't be json as that calls getContent
320+
// @see src/Symfony/Component/HttpClient/Exception/HttpExceptionTrait.php:58
321+
$this->assertStringNotContainsString('json', $e->getResponse()->getHeaders(false)['content-type'][0] ?? '');
322+
323+
$r = new \ReflectionProperty($client, 'multi');
324+
$r->setAccessible(true);
325+
/** @var ClientState $clientState */
326+
$clientState = $r->getValue($client);
327+
328+
$this->assertCount(0, $clientState->handlesActivity);
329+
$this->assertCount(0, $clientState->openHandles);
330+
}
331+
}
308332
}

Tests/MockHttpClientTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ 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+
243246
case 'testPause':
244247
case 'testPauseReplace':
245248
case 'testPauseDuringBody':

0 commit comments

Comments
 (0)