Skip to content

Commit

Permalink
fix: Fix possible exception-related ByteBuf leak (#99)
Browse files Browse the repository at this point in the history
#### Motivation

Some ByteBuf leak errors were reported in a production deployment of model-mesh as described in #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 <nickhill@us.ibm.com>
  • Loading branch information
njhill authored Jun 16, 2023
1 parent cef2b97 commit c4fc041
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/ibm/watson/modelmesh/ModelMeshApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -768,14 +768,17 @@ public void onHalfClose() {
evictMethodDescriptor(methodName);
}
} finally {
final boolean releaseResponse = status != OK;
if (payloadProcessor != null) {
ByteBuf data = null;
Metadata metadata = null;
if (response != null) {
data = response.data.readerIndex(respReaderIndex);
metadata = response.metadata;
}
processPayload(data, requestId, modelId, methodName, metadata, status, false);
processPayload(data, requestId, modelId, methodName, metadata, status, releaseResponse);
} else if (releaseResponse && response != null) {
response.release();
}
ReleaseAfterResponse.releaseAll();
clearThreadLocals();
Expand Down Expand Up @@ -805,7 +808,7 @@ private void processPayload(ByteBuf data, String payloadId, String modelId, Stri
try {
assert payloadProcessor != null;
if (!takeOwnership) {
data.retain();
ReferenceCountUtil.retain(data);
}
payload = new Payload(payloadId, modelId, methodName, metadata, data, status);
if (payloadProcessor.process(payload)) {
Expand Down

0 comments on commit c4fc041

Please sign in to comment.