Skip to content

Commit b5f7b9f

Browse files
author
Kyra Farrow
committed
bug #32989 [HttpClient] Declare $active first to prevent weird issue (Kocal)
This PR was squashed before being merged into the 4.3 branch (closes #32989). Discussion ---------- [HttpClient] Declare `$active` first to prevent weird issue | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | - <!-- please add some, will be required by reviewers --> | Fixed tickets | #32833 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | no In some undefined cases we can have the following error while using the WebTestCase/CurlHttpClient in PHPUnit: ![Sélection_999(101)](https://user-images.githubusercontent.com/2103975/62543336-0ad9e700-b85e-11e9-8b7f-d5b49e1d2d0d.png) This is really weird because `$active` is a reference and so it does not need to be declared before, but doing that fixes the issue. (symfony/symfony#32833 (comment)) I can't add tests because we were not able to reproduce the issue... Commits ------- ba030f0022 [HttpClient] Declare `$active` first to prevent weird issue
2 parents fc12f80 + 18b257e commit b5f7b9f

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

CurlHttpClient.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
290290
throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of CurlResponse objects, %s given.', __METHOD__, \is_object($responses) ? \get_class($responses) : \gettype($responses)));
291291
}
292292

293+
$active = 0;
293294
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->multi->handle, $active));
294295

295296
return new ResponseStream(CurlResponse::stream($responses, $timeout));
@@ -302,6 +303,7 @@ public function __destruct()
302303
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, null);
303304
}
304305

306+
$active = 0;
305307
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->multi->handle, $active));
306308

307309
foreach ($this->multi->openHandles as $ch) {

Response/CurlResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ private static function perform(CurlClientState $multi, array &$responses = null
255255

256256
try {
257257
self::$performing = true;
258+
$active = 0;
258259
while (CURLM_CALL_MULTI_PERFORM === curl_multi_exec($multi->handle, $active));
259260

260261
while ($info = curl_multi_info_read($multi->handle)) {

0 commit comments

Comments
 (0)