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

[HttpClient] Fix exception triggered with AsyncResponse #38378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

jderusse
Copy link
Member

@jderusse jderusse commented Oct 2, 2020

Q A
Branch? master
Bug fix? yes
New feature? no
Deprecations? no
Tickets #38289 (comment)
License MIT
Doc PR /

When a request is replayed with the AsyncResponse and the 2nd request failed, users get an exception even when they pass $throw=false.

In fact, there are 2 exceptions:

  1. Cannot get the content of the response twice: buffering is disabled.

if (null === $this->content) {
$content = null;
foreach (self::stream([$this]) as $chunk) {
if (!$chunk->isLast()) {
$content .= $chunk->getContent();
}
}
if (null !== $content) {
return $content;
}
if ('HEAD' === $this->getInfo('http_method') || \in_array($this->getInfo('http_code'), [204, 304], true)) {
return '';
}
throw new TransportException('Cannot get the content of the response twice: buffering is disabled.');

Because CommonResponseTrait::$content is null and self::stream yield only the LastChunk. The content is stays null

  1. HTTP/2 429 returned for "https://httpbin.org/status/429"

if (!$r->passthru) {
if (null !== $chunk->getError() || $chunk->isLast()) {
unset($asyncMap[$response]);
} elseif (null !== $r->content && '' !== ($content = $chunk->getContent()) && \strlen($content) !== fwrite($r->content, $content)) {
$chunk = new ErrorChunk($r->offset, new TransportException(sprintf('Failed writing %d bytes to the response buffer.', \strlen($content))));
$r->info['error'] = $chunk->getError();
$r->response->cancel();
}
yield $r => $chunk;
continue;
}
if (null === $chunk->getError() && $chunk->isFirst()) {
// Ensure no exception is thrown on destruct for the wrapped response
$r->response->getStatusCode();
}

Because on the second request passthru is null, it didn't disable the the exception thrown on destruct for the wrapped response.
This

@nicolas-grekas nicolas-grekas changed the title Fix exception triggered with AsyncResponse [HttpClient] Fix exception triggered with AsyncResponse Oct 2, 2020
@nicolas-grekas
Copy link
Member

Thank you @jderusse.

@nicolas-grekas nicolas-grekas merged commit 1f7b8fd into symfony:master Oct 2, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@jderusse jderusse deleted the fix-async branch October 15, 2020 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.