diff --git a/.chloggen/fix-memorylimiter.yaml b/.chloggen/fix-memorylimiter.yaml new file mode 100644 index 00000000000..a64c48e8563 --- /dev/null +++ b/.chloggen/fix-memorylimiter.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) +component: extension/memory_limiter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add support for streaming services. + +# One or more tracking issues or pull requests related to the change +issues: [14634] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/.chloggen/fix-memorylimiter_interceptor.yaml b/.chloggen/fix-memorylimiter_interceptor.yaml new file mode 100644 index 00000000000..b8ab31138fe --- /dev/null +++ b/.chloggen/fix-memorylimiter_interceptor.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: bug_fix + +# The name of the component, or a single word describing the area of concern, (e.g. receiver/otlp) +component: extension/memory_limiter + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Use ChainUnaryInterceptor instead of UnaryInterceptor to allow multiple interceptors. + +# One or more tracking issues or pull requests related to the change +issues: [14634] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: If multiple extensions that use the UnaryInterceptor are set the binary panics at start time. + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/extension/memorylimiterextension/memorylimiter.go b/extension/memorylimiterextension/memorylimiter.go index b2a795fe392..319c2741d82 100644 --- a/extension/memorylimiterextension/memorylimiter.go +++ b/extension/memorylimiterextension/memorylimiter.go @@ -60,12 +60,20 @@ func (ml *memoryLimiterExtension) GetHTTPHandler(base http.Handler) (http.Handle } func (ml *memoryLimiterExtension) GetGRPCServerOptions() ([]grpc.ServerOption, error) { - return []grpc.ServerOption{grpc.UnaryInterceptor( - func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { - if ml.MustRefuse() { - return nil, status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED") - } - return handler(ctx, req) - }, - )}, nil + return []grpc.ServerOption{ + grpc.ChainUnaryInterceptor( + func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) { + if ml.MustRefuse() { + return nil, status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED") + } + return handler(ctx, req) + }), + grpc.ChainStreamInterceptor( + func(srv any, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + if ml.MustRefuse() { + return status.Errorf(codes.ResourceExhausted, "RESOURCE_EXHAUSTED") + } + return handler(srv, ss) + }), + }, nil }