代码之家  ›  专栏  ›  技术社区  ›  Roddy of the Frozen Peas

在spring boot的嵌入式netty中增加或删除内容长度限制

  •  6
  • Roddy of the Frozen Peas  · 技术社区  · 6 年前

    2018-06-22 16:47:58.740 ERROR 11164 --- [ctor-http-nio-5] r.ipc.netty.channel.ContextHandler       : Error cannot be forwarded to user-facing Mono
    
    io.netty.handler.codec.TooLongFrameException: content length exceeded 65536 bytes.
        at io.netty.handler.codec.MessageAggregator.handleOversizedMessage(MessageAggregator.java:399) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.handler.codec.MessageAggregator.invokeHandleOversizedMessage(MessageAggregator.java:383) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.handler.codec.MessageAggregator.decode(MessageAggregator.java:277) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) [netty-codec-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-transport-4.1.24.Final.jar:4.1.24.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) [netty-common-4.1.24.Final.jar:4.1.24.Final]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]
    

    如何配置spring boot中的嵌入式netty,使其不受内容长度限制? 我无法控制在响应中返回的消息的长度。

    网关中的路由如下所示:

    - id: check_status_sockjs
      uri: http://foo.example.com:8080
      predicates:
        - Path=/foo/status/**
      filters:
        - RewritePath=/foo/status/(?<segment>.*), /status/$\{segment}
    

    我将sockjs请求路由到的另一端的服务也是一个spring引导应用程序,作为war部署在tomcat 8.5服务器中。当我直接与后台服务交互时,我不会遇到任何内容长度方面的问题——只有当我试图通过网关应用程序中的嵌入式Netty路由时。

    我在网关中的依赖项是:

    • 弹簧防尘套起动机执行器(2.0.2.释放)
    1 回复  |  直到 6 年前
        1
  •  5
  •   Andrei Damian-Fekete Daniel Warmuth    6 年前

    如何配置spring boot中的嵌入式netty,使其不受内容长度限制?

    目前 不可能 是的。 见 reactor-netty #223 Spring Framework #16228 是的。


    分析:

    结果发现netty显然有一个最大的内容长度

    限制来自 reactor-netty ,不是直接来自 Netty .

    限制来自 reactor. ... .WebsocketInbound ,一个Java接口 每帧总计65536字节 是的。

    我只能找到一个实现 WebsocketInbound 以下内容: HttpServerWSOperations .此类不会更改默认方法 WebsocketInbound.aggregateFrames 所以65k字节的限制仍然存在。

    HttpServerWs操作 最终的 方法 HttpServerOperations.withWebsocketSupport 它是直接实例化的,所以您不能更改实现。