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

spring cloud网关中使用北极星限流不生效 #1106

Closed
zev-223 opened this issue Sep 11, 2023 · 14 comments · Fixed by #1166, #1167, #1169 or #1168
Closed

spring cloud网关中使用北极星限流不生效 #1106

zev-223 opened this issue Sep 11, 2023 · 14 comments · Fixed by #1166, #1167, #1169 or #1168
Assignees
Labels
bug Something isn't working
Milestone

Comments

@zev-223
Copy link

zev-223 commented Sep 11, 2023

版本号:
spring-cloud-starter-gateway 2022.0.4
spring-cloud-starter-tencent-polaris-ratelimit 1.11.9-2022.0.1

spring-cloud-starter-gateway网关中集成北极星限流,匹配限流规则时限流未生效。后台报错信息: java.lang.IllegalArgumentException: Validation failed for header 'internal-callee-activerule'

限流规则配置
a

@zev-223 zev-223 added the question Further information is requested label Sep 11, 2023
@zev-223 zev-223 changed the title spring spring cloud网关中使用北极星限流不生效 Sep 11, 2023
@SkyeBeFreeman
Copy link
Collaborator

也发一下限流规则的配置

@SkyeBeFreeman
Copy link
Collaborator

详细的报错日志贴一下,看起来像是监控上报的时候没有正确读取到生效的限流规则。SCT会在这里塞入生效的限流规则名,然后监控上报时可以上报到北极星。
image

@zev-223
Copy link
Author

zev-223 commented Sep 11, 2023

详细的报错日志贴一下,看起来像是监控上报的时候没有正确读取到生效的限流规则。SCT会在这里塞入生效的限流规则名,然后监控上报时可以上报到北极星。 image

2023-09-11T16:13:20.857+08:00 ERROR 1 --- [or-http-epoll-4] c.t.c.p.r.f.QuotaCheckReactiveFilter : fail to invoke getQuota, service is irked-gateway

java.lang.IllegalArgumentException: Validation failed for header 'internal-callee-activerule'
at io.netty.handler.codec.DefaultHeaders.validateValue(DefaultHeaders.java:1019) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.DefaultHeaders.add(DefaultHeaders.java:330) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.DefaultHeaders.addObject(DefaultHeaders.java:364) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.http.DefaultHttpHeaders.add(DefaultHttpHeaders.java:115) ~[netty-codec-http-4.1.97.Final.jar!/:4.1.97.Final]
at org.springframework.http.server.reactive.NettyHeadersAdapter.add(NettyHeadersAdapter.java:59) ~[spring-web-6.0.11.jar!/:6.0.11]
at org.springframework.http.server.reactive.NettyHeadersAdapter.add(NettyHeadersAdapter.java:40) ~[spring-web-6.0.11.jar!/:6.0.11]
at org.springframework.http.HttpHeaders.add(HttpHeaders.java:1725) ~[spring-web-6.0.11.jar!/:6.0.11]
at com.tencent.cloud.polaris.ratelimit.filter.QuotaCheckReactiveFilter.filter(QuotaCheckReactiveFilter.java:122) ~[spring-cloud-starter-tencent-polaris-ratelimit-1.11.9-2022.0.1.jar!/:1.11.9-2022.0.1]
at org.springframework.web.server.handler.DefaultWebFilterChain.invokeFilter(DefaultWebFilterChain.java:114) ~[spring-web-6.0.11.jar!/:6.0.11]
at org.springframework.web.server.handler.DefaultWebFilterChain.lambda$filter$0(DefaultWebFilterChain.java:108) ~[spring-web-6.0.11.jar!/:6.0.11]
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:53) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.Mono.subscribe(Mono.java:4495) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.MonoIgnoreThen$ThenIgnoreMain.subscribeNext(MonoIgnoreThen.java:263) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.MonoIgnoreThen.subscribe(MonoIgnoreThen.java:51) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.core.publisher.MonoDeferContextual.subscribe(MonoDeferContextual.java:55) ~[reactor-core-3.5.9.jar!/:3.5.9]
at reactor.netty.http.server.HttpServer$HttpServerHandle.onStateChange(HttpServer.java:1052) ~[reactor-netty-http-1.1.10.jar!/:1.1.10]
at reactor.netty.ReactorNetty$CompositeConnectionObserver.onStateChange(ReactorNetty.java:710) ~[reactor-netty-core-1.1.10.jar!/:1.1.10]
at reactor.netty.transport.ServerTransport$ChildObserver.onStateChange(ServerTransport.java:481) ~[reactor-netty-core-1.1.10.jar!/:1.1.10]
at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:647) ~[reactor-netty-http-1.1.10.jar!/:1.1.10]
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:114) ~[reactor-netty-core-1.1.10.jar!/:1.1.10]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:238) ~[reactor-netty-http-1.1.10.jar!/:1.1.10]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800) ~[netty-transport-classes-epoll-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:509) ~[netty-transport-classes-epoll-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:407) ~[netty-transport-classes-epoll-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.97.Final.jar!/:4.1.97.Final]
at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: java.lang.IllegalArgumentException: a header value contains prohibited character 0x6d4b at index 0.
at io.netty.handler.codec.http.DefaultHttpHeaders$HeaderValueValidator.validate(DefaultHttpHeaders.java:395) ~[netty-codec-http-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.http.DefaultHttpHeaders$HeaderValueValidator.validate(DefaultHttpHeaders.java:387) ~[netty-codec-http-4.1.97.Final.jar!/:4.1.97.Final]
at io.netty.handler.codec.DefaultHeaders.validateValue(DefaultHeaders.java:1017) ~[netty-codec-4.1.97.Final.jar!/:4.1.97.Final]
... 47 common frames omitted

2023-09-11T16:13:32.056+08:00 ERROR 1 --- [or-http-epoll-1] m.c.DecodeTransferMetadataReactiveFilter : handle metadata[MetadataContext{fragmentContexts={"transitive":{},"disposable":{"source_service_namespace":"irked-cloud-polaris","source_service_name":"irked-gateway"}}}] error.

@SkyeBeFreeman
Copy link
Collaborator

你这边有直接或者间接引入netty相关依赖吗?我看了下netty的版本不匹配

@zev-223
Copy link
Author

zev-223 commented Sep 11, 2023

你这边有直接或者间接引入netty相关依赖吗?我看了下netty的版本不匹配

嗯,的确是netty版本的问题,springcloud 版本降到 2022.0.2 及以下版本就正常了

@SkyeBeFreeman
Copy link
Collaborator

SkyeBeFreeman commented Sep 11, 2023

这个版本问题在下个版本升级2022版本时会关注修复。如果您有兴趣,可以提交PR参与共建。

@zev-223
Copy link
Author

zev-223 commented Sep 11, 2023

这个版本问题在下个版本升级2022版本时会关注修复。如果您有兴趣,可以提交PR参与共建。

好的,感谢

@zev-223 zev-223 closed this as completed Sep 11, 2023
@SkyeBeFreeman SkyeBeFreeman reopened this Sep 11, 2023
@SkyeBeFreeman SkyeBeFreeman added this to the 1.13.0 milestone Sep 11, 2023
@SkyeBeFreeman SkyeBeFreeman added bug Something isn't working enhancement New feature or request and removed question Further information is requested bug Something isn't working enhancement New feature or request labels Sep 11, 2023
@SkyeBeFreeman
Copy link
Collaborator

@zev-223 使用1.12.1-2022.0.4版本的SDK看下能否复现呢?我这里暂时不能复现出来。

@zev-223
Copy link
Author

zev-223 commented Sep 27, 2023

@zev-223 使用1.12.1-2022.0.4版本的SDK看下能否复现呢?我这里暂时不能复现出来。

a

我试了一下,还是有的
几个核心版本号:
<spring.cloud.version>2022.0.4</spring.cloud.version>
<spring.cloud.tencent.version>1.12.1-2022.0.4</spring.cloud.tencent.version>
<spring.boot.version>3.1.3</spring.boot.version>

@SkyeBeFreeman
Copy link
Collaborator

问题应该出在spring boot版本为3.1.x,我再试试

@SkyeBeFreeman
Copy link
Collaborator

@zev-223 使用1.12.1-2022.0.4版本的SDK看下能否复现呢?我这里暂时不能复现出来。

a

我试了一下,还是有的 几个核心版本号: <spring.cloud.version>2022.0.4</spring.cloud.version> <spring.cloud.tencent.version>1.12.1-2022.0.4</spring.cloud.tencent.version> <spring.boot.version>3.1.3</spring.boot.version>

我这边还是没有复现出来。你这个报错是出现在校验头部值的时候出现的,建议发一下你的限流规则名称,并debug到这个方法,io.netty.handler.codec.DefaultHeaders#validateValue,看看是哪个环节校验出问题。

@SkyeBeFreeman SkyeBeFreeman removed this from the 1.13.0 milestone Oct 7, 2023
@zev-223
Copy link
Author

zev-223 commented Oct 8, 2023

问题应该出在spring boot版本为3.1.x,我再试试

本地debug了一下,发现请求头“internal-callee-activerule”,传递的value值为 配置的限流规则名称,如果这个名称为中文时会出现上面的错误

@SkyeBeFreeman SkyeBeFreeman reopened this Oct 9, 2023
@SkyeBeFreeman
Copy link
Collaborator

这里我后面验证一下,是否为高版本netty做了校验限制

@SkyeBeFreeman SkyeBeFreeman added this to the 1.13.0 milestone Oct 9, 2023
@SkyeBeFreeman
Copy link
Collaborator

我这边验证了一下,确实有这个问题。修复方案如下:

  1. HTTP头部塞入internal-callee-activerule时,需将value通过UTF-8进行encode。
  2. 从HTTP头部取出internal-callee-activerule时,需将value通过UTF-8进行decode。

@SkyeBeFreeman SkyeBeFreeman self-assigned this Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment