-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
[Question] reject request without paying deserialization cost #311
Comments
You can't implement this purely in a marshaller, as the marshaller only has access to a |
@JamesNK what do you think? Someone seems to have put an interceptor + marshaller recipe for java here: https://groups.google.com/g/grpc-io/c/lrSj2iuMx3A. Do you know if we have these equivalents in protobuf-net? |
I am also flexible in terms of how we communicate the priority, if there is a different non-header way that makes it easier. |
You need to have middleware before gRPC. Maybe you could use ASP.NET Core rate limiting? https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit?view=aspnetcore-7.0 |
The question isn't about "in protobuf-net" - protobuf-net.Grpc sits on top of the Goggle/Microsoft gRPC server implementation - and the |
I agree that I don't think anything exists today, but: should something better exist here? perhaps a new method on |
Middleware is a shared layer between all ASP.NET Core frameworks, and keeping the logic there and recommending rate-limiting middleware for this task reduces duplication of code and concepts. Perhaps having access to public Task Invoke(HttpContext context)
{
var endpoint = context.GetEndpoint();
var grpcMethodMetadata = endpoint.Metadata.GetMetadata<GrpcMethodMetadata>();
// ...
} |
@JamesNK if I do use this middleware approach, how can I return a grpc error code? I can only return an http status from within a middleware. How do these get mapped to grpc errors, and what will the client see? |
A grpc error is just a trailer. You can add a trailer to the HttpResponse. Alternatively you can return a regular HTTP status code and clients will map it to a gRPC status code. |
I got this to mostly work with the following code in my custom middleware:
This mostly works as expected, but I get these errors intermittently from my load test client: ERROR: server 'http://localhost:23400/V3/grpc' is not online. Unable to connect. e=Status(StatusCode="ResourceExhausted", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The request was aborted. Http2StreamException: The HTTP/2 server reset the stream. HTTP/2 error code 'ENHANCE_YOUR_CALM' (0xb).", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.") @JamesNK I read your response here about
|
Context: I have a grpc server that supports high & low priority traffic. If it gets too many requests I want to reject low priority traffic (return ResourceExhausted). Low pri traffic is identifiable by a priority int that is sent as a RequestHeader from the client. I am on ASP.NET core
However, I would be able to like to do this without deserializing the message so that my server can't get knocked over just by sending it a ton of traffic. Doing this at the load balancer level is a bit difficult for us right now.
From what I've seen online, the right way to go seems to be:
I was wondering if there is built in support to do something like this without requiring a custom marshaller? Maybe an interceptor only solution? I imagine that this is a relatively common use case.
The text was updated successfully, but these errors were encountered: