Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dff71ce

Browse filesBrowse files
bug #33691 [HttpClient] fix race condition when reading response with informational status (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] fix race condition when reading response with informational status | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Spotted by some transiently failing jobs on Travis. Commits ------- 450c3c4 [HttpClient] fix race condition when reading response with informational status
2 parents c8dbd1a + 450c3c4 commit dff71ce
Copy full SHA for dff71ce

File tree

4 files changed

+13
-5
lines changed
Filter options

4 files changed

+13
-5
lines changed

‎src/Symfony/Component/HttpClient/CurlHttpClient.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/CurlHttpClient.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ private static function handlePush($parent, $pushed, array $requestHeaders, Curl
355355
*/
356356
private static function acceptPushForRequest(string $method, array $options, PushedResponse $pushedResponse): bool
357357
{
358-
if ($options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
358+
if ('' !== $options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
359359
return false;
360360
}
361361

‎src/Symfony/Component/HttpClient/Response/CurlResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/CurlResponse.php
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ public function __construct(CurlClientState $multi, $ch, array $options = null,
121121

122122
if (\in_array($waitFor, ['headers', 'destruct'], true)) {
123123
try {
124-
self::stream([$response])->current();
124+
foreach (self::stream([$response]) as $chunk) {
125+
if ($chunk->isFirst()) {
126+
break;
127+
}
128+
}
125129
} catch (\Throwable $e) {
126130
// Persist timeouts thrown during initialization
127131
$response->info['error'] = $e->getMessage();
128132
$response->close();
129133
throw $e;
130134
}
131-
} elseif ('content' === $waitFor && ($response->multi->handlesActivity[$response->id][0] ?? null) instanceof FirstChunk) {
132-
self::stream([$response])->current();
133135
}
134136

135137
curl_setopt($ch, CURLOPT_HEADERFUNCTION, null);

‎src/Symfony/Component/HttpClient/Response/NativeResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/NativeResponse.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public function __construct(NativeClientState $multi, $context, string $url, $op
6565
}
6666

6767
if (null === $response->remaining) {
68-
self::stream([$response])->current();
68+
foreach (self::stream([$response]) as $chunk) {
69+
if ($chunk->isFirst()) {
70+
break;
71+
}
72+
}
6973
}
7074
};
7175
}

‎src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/HttpClient/Test/Fixtures/web/index.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
header('HTTP/1.1 103 Early Hints');
4646
header('Link: </style.css>; rel=preload; as=style', false);
4747
header('Link: </script.js>; rel=preload; as=script', false);
48+
flush();
49+
usleep(1000);
4850
echo "HTTP/1.1 200 OK\r\n";
4951
echo "Date: Fri, 26 May 2017 10:02:11 GMT\r\n";
5052
echo "Content-Length: 13\r\n";

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.