Merge branch '4.2.x'

This commit is contained in:
Ryan Baxter
2025-03-14 10:45:27 -04:00

View File

@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType;
import reactor.netty.Connection;
import org.springframework.core.Ordered;
@@ -98,8 +99,12 @@ public class NettyWriteResponseFilter implements GlobalFilter, Ordered {
return (isStreamingMediaType(contentType)
? response.writeAndFlushWith(body.map(Flux::just))
: response.writeWith(body));
})).doOnCancel(() -> cleanup(exchange))
.doOnError(throwable -> cleanup(exchange));
}))
.doFinally(signalType -> {
if (signalType == SignalType.CANCEL || signalType == SignalType.ON_ERROR) {
cleanup(exchange);
}
});
// @formatter:on
}
@@ -116,12 +121,12 @@ public class NettyWriteResponseFilter implements GlobalFilter, Ordered {
byteBuf.release();
return buffer;
}
throw new IllegalArgumentException("Unkown DataBufferFactory type " + bufferFactory.getClass());
throw new IllegalArgumentException("Unknown DataBufferFactory type " + bufferFactory.getClass());
}
private void cleanup(ServerWebExchange exchange) {
Connection connection = exchange.getAttribute(CLIENT_RESPONSE_CONN_ATTR);
if (connection != null && connection.channel().isActive()) {
if (connection != null) {
connection.dispose();
}
}