网关gateway出现netty_data_buffer(OOM)内存溢出问题

本文介绍了在使用Spring Cloud Gateway Hoxton.RELEASE版本时遇到的内存溢出问题,特别是在开启限流和压测后,由于netty_data_buffer的内存逐渐增大导致。问题根源在于ReadBodyPredicateFactory中请求体缓存以及ServerWebExchangeUtils中静态公有字符串KEY值的过度使用。解决方案是针对databuffer进行适当的内存释放操作,以防止内存持续增长引发的溢出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

现象描述

  1. 网关Hoxton.RELEASE版本,接入Apollo。
  2. 在项目开启限流、压测一段时间后,netty_data_buffer的内存逐渐变大,最终导致内存溢出。
  3. 项目在运行过程中开启了ReadBodyPredicateFactory断言。

问题定位

        1、在ReadBodyPredicateFactory中进行请求体缓存。

public class ReadBodyPredicateFactory
		extends AbstractRoutePredicateFactory<ReadBodyPredicateFactory.Config> {
	...
	
	@Override
	@SuppressWarnings("unchecked")
	public AsyncPredicate<ServerWebExchange> applyAsync(Config config) {
		return exchange -> {
			Class inClass = config.getInClass();

			Object cachedBody = exchange.getAttribute(CACHE_REQUEST_BODY_OBJECT_KEY);
			Mono<?> modifiedBody;
			// We can only read the body from the request once, once that happens if we
			// try to read the body again an exception will be thrown. The below if/else
			// caches the body object as a request attribute in the ServerWebExchange
			// so if this filter is run more than o
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值