Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed netty leak on DELETE operations in GATEWAY mode #14727

Merged
Show file tree
Hide file tree
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 @@ -246,17 +246,9 @@ private Mono<RxDocumentServiceResponse> toDocumentServiceResponse(Mono<HttpRespo
HttpHeaders httpResponseHeaders = httpResponse.headers();
int httpResponseStatus = httpResponse.statusCode();

Mono<byte[]> contentObservable;

if (request.getOperationType() == OperationType.Delete) {
// for delete we don't expect any body
contentObservable = Mono.just(EMPTY_BYTE_ARRAY);
} else {
// transforms the ByteBufFlux to Flux<String>
contentObservable = httpResponse
.bodyAsByteArray()
.switchIfEmpty(Mono.just(EMPTY_BYTE_ARRAY));
}
Mono<byte[]> contentObservable = httpResponse
.bodyAsByteArray()
.switchIfEmpty(Mono.just(EMPTY_BYTE_ARRAY));

return contentObservable
.map(content -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public class ErrorUtils {
private static final Logger logger = LoggerFactory.getLogger(ErrorUtils.class);

static Mono<String> getErrorResponseAsync(HttpResponse responseMessage, HttpRequest request) {
Mono<String> responseAsString = responseMessage.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY));
if (request.httpMethod() == HttpMethod.DELETE) {
return Mono.just(StringUtils.EMPTY);
}
return responseAsString;
return responseMessage.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY));
}

static void logGoneException(URI physicalAddress, String activityId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@
import reactor.core.publisher.Mono;

class ResponseUtils {
private static byte[] EMPTY_BYTE_ARRAY = {};
private static final byte[] EMPTY_BYTE_ARRAY = {};

static Mono<StoreResponse> toStoreResponse(HttpResponse httpClientResponse, HttpRequest httpRequest) {

HttpHeaders httpResponseHeaders = httpClientResponse.headers();

Mono<byte[]> contentObservable;

if (httpRequest.httpMethod() == HttpMethod.DELETE) {
// for delete we don't expect any body
contentObservable = Mono.just(EMPTY_BYTE_ARRAY);
} else {
contentObservable = httpClientResponse.bodyAsByteArray().switchIfEmpty(Mono.just(EMPTY_BYTE_ARRAY));
}
Mono<byte[]> contentObservable = httpClientResponse.bodyAsByteArray().switchIfEmpty(Mono.just(EMPTY_BYTE_ARRAY));

return contentObservable.map(byteArrayContent -> {
// transforms to Mono<StoreResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,7 @@ public HttpHeaders headers() {
@Override
public Flux<ByteBuf> body() {
return bodyIntern()
.doOnSubscribe(this::updateSubscriptionState)
.map(byteBuf -> {
byteBuf.retain();
return byteBuf;
});
.doOnSubscribe(this::updateSubscriptionState);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what this change for ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removed the unnecessary map operator. We don't need to retain the byteBuf here, as it is not released afterwards.
This can potentially raise IllegalReferenceCount issue with netty.
Although, we don't use this API, which is why no one has seen this issue.

}

@Override
Expand Down