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

Block remote adapter url and handler override #1147

Merged
merged 3 commits into from
Oct 4, 2023

Conversation

zachgk
Copy link
Contributor

@zachgk zachgk commented Oct 3, 2023

No description provided.

@zachgk zachgk requested review from frankfliu and a team as code owners October 3, 2023 23:23
@@ -92,6 +92,11 @@ public Input parseRequest(FullHttpRequest req, QueryStringDecoder decoder) {
byte[] content = NettyUtils.getBytes(req.content());
input.add("data", content);
}

if (input.getProperties().containsKey("handler")) {
throw new BadRequestException("The handler can't be overridden in a request");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we want to block handler override?

This at least should be an option (a global conf.properties) to disable handler override if we want disable it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote a comment about this in slack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@frankfliu If we want to support this, I think it should be a property to enable rather than disable. Do you know if we have users using custom handlers now?

Copy link
Contributor

Choose a reason for hiding this comment

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

This was designed to allow user to call pre/postprocessing:

https://github.com/deepjavalibrary/djl-demo/tree/master/development/python

Copy link
Contributor

Choose a reason for hiding this comment

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

We can default to disable handler override

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After more thought, I don't think it is something we want to support at all. But, here are two workarounds that give very similar results:

1 - Share model.py

We keep the ability to change the handler in the serving.properties. Then, you can symlink the model.py around to share it. This will still result in different workers for the model and pre-post processing unless we change something.

2 - Sub-handler

subHandlers = {
  "pre" : (lambda inputs: ...),
  "m" : (lambda inputs: ...),
  "post" : (lambda inputs: ...),
}

def handler(inputs):
  return subHandlers[inputs.getProperty("subHandler")](inputs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can leave this discussion for later. For now, I added an env/system prop ALLOW_REQUEST_HANDLER_OVERRIDE to re-enable handler overrides

@zachgk zachgk merged commit d54c870 into deepjavalibrary:master Oct 4, 2023
7 checks passed
@zachgk zachgk deleted the adaptMal branch October 4, 2023 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants