HttpClient upstream cancellation when inbound request aborts before upstream response completes
0 reputation · 03 Aug 2021, 06:19 UTC
0 reputation · 03 Aug 2021, 06:19 UTC
Symfony HttpClient executes upstream calls with its own timeout configuration (timeout, max_duration, stream timeout) that operates independently of the enclosing HTTP request lifecycle. When a client disconnects early—closing the browser tab, cancelling a fetch, or hitting a reverse-proxy timeout—the inbound Symfony request terminates, but the outbound HttpClient request continues until its own limits are reached.
Applications running on Symfony 6.4 or 7.x with the default cURL transport need upstream calls to stop promptly when the outer request is aborted, avoiding worker saturation and connection-pool exhaustion. The framework does not automatically propagate the inbound cancellation to the HttpClient response by default.
timeout, max_duration, stream) and kernel event listeners (kernel.terminate, kernel.request connection status checks) reliably cancels the upstream call across both cURL and stream transports?Symfony\Contracts\HttpClient\HttpClientInterface with a custom Symfony\Component\HttpClient\Response\CancellableResponseInterface implementation provide deterministic cleanup without version-specific transport hacks?config/packages/http_client.yaml that guarantee cancellation propagation for Symfony 6.4 LTS and 7.x without requiring per-controller boilerplate?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.