This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 3227d347d1e98e4ea9db2c9703082e8a01abee76 Author: Michael Blow <[email protected]> AuthorDate: Thu Sep 28 19:30:53 2023 -0400 [NO ISSUE][HYR][HTTP] Avoid double release of ChunkedNettyOutputStream buffer Change-Id: I1c7f5221a52cbcdb8c0818d7156760bf6b72ee08 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17821 Integration-Tests: Jenkins <[email protected]> Reviewed-by: Michael Blow <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Tested-by: Jenkins <[email protected]> --- .../http/server/ChunkedNettyOutputStream.java | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedNettyOutputStream.java b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedNettyOutputStream.java index 9a940b1159..b313cbb2d9 100644 --- a/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedNettyOutputStream.java +++ b/hyracks-fullstack/hyracks/hyracks-http/src/main/java/org/apache/hyracks/http/server/ChunkedNettyOutputStream.java @@ -21,6 +21,7 @@ package org.apache.hyracks.http.server; import java.io.IOException; import java.io.OutputStream; +import org.apache.hyracks.api.util.InvokeUtil; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -81,20 +82,22 @@ public class ChunkedNettyOutputStream extends OutputStream { @Override public void close() throws IOException { if (!closed) { - if (response.isHeaderSent() || response.status() != HttpResponseStatus.OK) { - try { + InvokeUtil.tryIoWithCleanups(() -> { + if (response.isHeaderSent() || response.status() != HttpResponseStatus.OK) { flush(); - } finally { - if (buffer != null) { - buffer.release(); - } + } else { + response.fullResponse(buffer); + // The responsibility of releasing the buffer is now with the netty pipeline since it is + // forwarded within the http content. We must nullify buffer to avoid releasing the buffer twice. + buffer = null; } - } else { - response.fullResponse(buffer); - } - super.close(); + super.close(); + }, () -> { + if (buffer != null) { + buffer.release(); + } + }, () -> closed = true); } - closed = true; } @Override
