8000 bug #45073 [HttpClient] Fix Failed to open stream: Too many open file… · symfony/symfony@d0a8092 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0a8092

Browse files
bug #45073 [HttpClient] Fix Failed to open stream: Too many open files (adrienfr)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Fix Failed to open stream: Too many open files | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #44900 | License | MIT With a large PHPUnit tests suite, I receive this error "Failed to open stream: Too many open files". I found the original code from `@nicolas`-grekas [here](https://github.com/symfony/symfony/pull/30413/files#diff-bbfff9335ca4f0716566920d7f427036c2d6f9ac2a9cb33e2c83514423ab4b14R77) and with small adjustments, it resolves my issue. Warning: tests for HttpClient are OK but would someone try with a real HTTP/2 client push? I was not able to test it. Commits ------- 40d22b8 [HttpClient] Fix Failed to open stream: Too many open files
2 parents 3838696 + 40d22b8 commit d0a8092

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Symfony/Component/HttpClient/Internal/CurlClientState.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
final class CurlClientState extends ClientState
2525
{
26-
/** @var \CurlMultiHandle|resource */
26+
/** @var \CurlMultiHandle|resource|null */
2727
public $handle;
28-
/** @var \CurlShareHandle|resource */
28+
/** @var \CurlShareHandle|resource|null */
2929
public $share;
3030
/** @var PushedResponse[] */
3131
public $pushedResponses = [];
@@ -65,8 +65,17 @@ public function __construct(int $maxHostConnections, int $maxPendingPushes)
6565
return;
6666
}
6767

68-
curl_multi_setopt($this->handle, \CURLMOPT_PUSHFUNCTION, function ($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) {
69-
return $this->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
68+
// Clone to prevent a circular reference
69+
$multi = clone $this;
70+
$multi->handle = null;
71+
$multi->share = null;
72+
$multi->pushedResponses = &$this->pushedResponses;
73+
$multi->logger = &$this->logger;
74+
$multi->handlesActivity = &$this->handlesActivity;
75+
$multi->openHandles = &$this->openHandles;
76+
77+
curl_multi_setopt($this->handle, \CURLMOPT_PUSHFUNCTION, static function ($parent, $pushed, array $requestHeaders) use ($multi, $maxPendingPushes) {
78+
return $multi->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
7079
});
7180
}
7281

0 commit comments

Comments
 (0)
0