Skip to content

Commit 5c12229

Browse files
author
Daniel Mikusa
authored
Ensure connections are closed in the event of a 401 & retry. (#1118)
Previously when a 401 would occur, we would throw the InvalidTokenException which in turn would trigger a retry. The retry would allow the TokenProvider to fetch a new, possibly valid token. When this happened, you could get into a state where reactor-netty was waiting for the library to finish using the connection (either consume the body or dispose it). Since we never did that, you could accumulate connections in the ESTABLISHED state. This code change will read and throw away the body when there's a 401, which signals to reactor-netty that it can reuse the connection. Signed-off-by: Daniel Mikusa <[email protected]>
1 parent 52f1caa commit 5c12229

File tree

1 file changed

+3
-0
lines changed
  • cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/util

1 file changed

+3
-0
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/util/Operator.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ private Flux<HttpClientResponseWithConnection> invalidateToken(Flux<HttpClientRe
245245
.doOnNext(response -> {
246246
if (isUnauthorized(response)) {
247247
this.context.getTokenProvider().ifPresent(tokenProvider -> tokenProvider.invalidate(this.context.getConnectionContext()));
248+
// we don't need the body, but we need to consume the body so reactor-netty can reuse the connection
249+
// if not, this will result in connections that don't close & the pool will fill up
250+
response.getConnection().inbound().receive().doOnNext(byteBuf -> {}).subscribe(byteBuf -> {}, ex -> {});
248251
throw new InvalidTokenException();
249252
}
250253
});

0 commit comments

Comments
 (0)