Skip to content

Commit 3ecb4b6

Browse files
committed
dispose the connection regardless of the channel state
Signed-off-by: raccoonback <kosb15@naver.com>
1 parent 2f73ed2 commit 3ecb4b6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/NettyWriteResponseFilter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.commons.logging.LogFactory;
2424
import reactor.core.publisher.Flux;
2525
import reactor.core.publisher.Mono;
26+
import reactor.core.publisher.SignalType;
2627
import reactor.netty.Connection;
2728

2829
import org.springframework.core.Ordered;
@@ -98,8 +99,12 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
9899
return (isStreamingMediaType(contentType)
99100
? response.writeAndFlushWith(body.map(Flux::just))
100101
: response.writeWith(body));
101-
})).doOnCancel(() -> cleanup(exchange))
102-
.doOnError(throwable -> cleanup(exchange));
102+
}))
103+
.doFinally(signalType -> {
104+
if (signalType == SignalType.CANCEL || signalType == SignalType.ON_ERROR) {
105+
cleanup(exchange);
106+
}
107+
});
103108
// @formatter:on
104109
}
105110

@@ -121,7 +126,7 @@ else if (bufferFactory instanceof DefaultDataBufferFactory) {
121126

122127
private void cleanup(ServerWebExchange exchange) {
123128
Connection connection = exchange.getAttribute(CLIENT_RESPONSE_CONN_ATTR);
124-
if (connection != null && connection.channel().isActive()) {
129+
if (connection != null) {
125130
connection.dispose();
126131
}
127132
}

0 commit comments

Comments
 (0)