Skip to content

Commit 26f4b1d

Browse 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 ------- 450c3c4998 [HttpClient] fix race condition when reading response with informational status
2 parents 917d2e9 + 66ad96a commit 26f4b1d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

CurlHttpClient.php

Lines 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

Response/CurlResponse.php

Lines 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);

Response/NativeResponse.php

Lines 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
}

0 commit comments

Comments
 (0)