Skip to content

Commit c4fc041

Browse files
authored
fix: Fix possible exception-related ByteBuf leak (kserve#99)
#### Motivation Some ByteBuf leak errors were reported in a production deployment of model-mesh as described in kserve#97. #### Modifications In `ModelMeshApi`, ensure that the response is released if a runtime exception is thrown prior to it being sent successfully. #### Result Hopefully leak closed Signed-off-by: Nick Hill <[email protected]>
1 parent cef2b97 commit c4fc041

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/com/ibm/watson/modelmesh/ModelMeshApi.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,17 @@ public void onHalfClose() {
768768
evictMethodDescriptor(methodName);
769769
}
770770
} finally {
771+
final boolean releaseResponse = status != OK;
771772
if (payloadProcessor != null) {
772773
ByteBuf data = null;
773774
Metadata metadata = null;
774775
if (response != null) {
775776
data = response.data.readerIndex(respReaderIndex);
776777
metadata = response.metadata;
777778
}
778-
processPayload(data, requestId, modelId, methodName, metadata, status, false);
779+
processPayload(data, requestId, modelId, methodName, metadata, status, releaseResponse);
780+
} else if (releaseResponse && response != null) {
781+
response.release();
779782
}
780783
ReleaseAfterResponse.releaseAll();
781784
clearThreadLocals();
@@ -805,7 +808,7 @@ private void processPayload(ByteBuf data, String payloadId, String modelId, Stri
805808
try {
806809
assert payloadProcessor != null;
807810
if (!takeOwnership) {
808-
data.retain();
811+
ReferenceCountUtil.retain(data);
809812
}
810813
payload = new Payload(payloadId, modelId, methodName, metadata, data, status);
811814
if (payloadProcessor.process(payload)) {

0 commit comments

Comments
 (0)