现象描述
- 网关Hoxton.RELEASE版本,接入Apollo。
- 在项目开启限流、压测一段时间后,netty_data_buffer的内存逐渐变大,最终导致内存溢出。
- 项目在运行过程中开启了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