Spring / Spring Cloud Gateway
Merged upstreamCorrectnessMerged Aug 7, 2026

Avoid draining failed streaming proxy responses

Fixed Spring Cloud Gateway MVC proxy cleanup so failed streaming responses close the active response body stream directly instead of draining long-lived SSE content.

spring-cloud/spring-cloud-gateway · #4217

Problem

Gateway MVC could leak downstream Server-Sent Events connections after a client disconnected. Some ClientHttpResponse implementations drain remaining content during close(), which can hang indefinitely for long-lived SSE streams and keep the backend connection open.

Approach

Changed streaming response copy failure cleanup to close the active response body stream directly, while preserving ClientHttpResponse.close() for normal completion and non-streaming error cleanup.

Impact and scope

  • Prevents disconnected MVC gateway clients from leaving long-lived SSE backend connections open.
  • Improves parity with the reactive gateway behavior for streaming disconnect scenarios.
  • Keeps non-streaming and normal-response cleanup behavior unchanged, limiting the fix to the failure path that can hang.

Validation

  • Added RestClientProxyExchangeTests coverage for failed streaming proxy response cleanup.
  • Updated both RestClient and ClientHttpRequestFactory proxy exchange paths.
  • Merged with focused Spring Cloud Gateway MVC proxy exchange tests documented in the PR.