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

Fix "direct buffer access" issue for Plugin SDK #2511

Merged
merged 4 commits into from
Aug 4, 2023
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 @@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
import org.pytorch.serve.servingsdk.http.Request;
import org.pytorch.serve.util.NettyUtils;

public class ModelServerRequest implements Request {
private FullHttpRequest req;
Expand Down Expand Up @@ -45,6 +46,6 @@ public String getContentType() {

@Override
public ByteArrayInputStream getInputStream() {
return new ByteArrayInputStream(req.content().array());
return new ByteArrayInputStream(NettyUtils.getBytes(req.content()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.pytorch.serve.util;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.pytorch.serve.servingsdk.http.Request;
import org.pytorch.serve.servingsdk.impl.ModelServerRequest;
import org.testng.Assert;
import org.testng.annotations.Test;

public class PluginSdkTest {
@Test
public void testReadRequestBodyFromPlugin() throws IOException {
ByteBuf buf = Unpooled.directBuffer();
buf.writeBytes("test".getBytes());
FullHttpRequest req =
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "", buf);
Request request = new ModelServerRequest(req, new QueryStringDecoder(""));
String line =
new BufferedReader(new InputStreamReader(request.getInputStream())).readLine();
Assert.assertEquals(line, "test");
}
}
1 change: 1 addition & 0 deletions frontend/server/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<classes>
<class name="org.pytorch.serve.util.ConfigManagerTest"/>
<class name="org.pytorch.serve.util.ConnectorTest"/>
<class name="org.pytorch.serve.util.PluginSdkTest"/>
<class name="org.pytorch.serve.CoverageTest"/>
<class name="org.pytorch.serve.ModelServerTest"/>
<class name="org.pytorch.serve.SnapshotTest"/>
Expand Down