DataBufferLimitException:Exceeded limit on max bytes to buffer : 262144

问题背景

DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144

问题的产生原因很容易查到,REST API接口请求数据超过256K,被网关拦截。正常我们加大缓冲区的配置即可,-1表示不限制。但是并没有解决问题,下面介绍我的分析过程和解决办法。

spring:
  codec:
    max-in-memory-size: 1048576

异常信息

org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144
	at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:98) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
	|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
	|_ checkpoint ⇢ HTTP POST "/ho-server/epc/collision/saveRecord" [ExceptionHandlingWebHandler]
Stack trace:
		at org.springframework.core.io.buffer.LimitedDataBufferList.raiseLimitException(LimitedDataBufferList.java:98) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
		at org.springframework.core.io.buffer.LimitedDataBufferList.updateCount(LimitedDataBufferList.java:91) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
		at org.springframework.core.io.buffer.LimitedDataBufferList.add(LimitedDataBufferList.java:57) ~[spring-core-5.2.15.RELEASE.jar:5.2.15.RELEASE]
		at reactor.core.publisher.MonoCollect$CollectSubscriber.onNext(MonoCollect.java:111) [reactor-core-3.3.17.RELEASE.jar:3.3.17.RELEASE]
		at reactor.core.publisher.Operators$ScalarSubscription.request(Operators.java:2393) ~[reactor-core-3.3.17.RELEASE.jar:3.3.17.RELEASE]
		at reactor.core.publisher.MonoCollect$CollectSubscriber.onSubscribe(MonoCollect.java:96) [reactor-core-3.3.17.RELEASE.jar:3.3.17.RELEASE]

解决办法

新增包名org.springframework.core.codec 覆盖 AbstractDataBufferDecoder方法

将maxInMemorySize 修改成需要的大小(项目上亲测有效)

private int maxInMemorySize = 5 * 1024 * 1024;代表能够缓存5M数据 默认是256kb

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值