Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -98,8 +99,12 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
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
}

Expand All @@ -116,12 +121,12 @@ else if (bufferFactory instanceof DefaultDataBufferFactory) {
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();
}
}
Expand Down
Loading