spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.52k stars 3.32k forks source link

add json to header thread leak #2029

Closed jipeigong closed 3 years ago

jipeigong commented 3 years ago

Describe the bug

my version: springcloud:Greenwich.SR1 springboot:2.1.5.RELEASE

I think this is a common phenomenon; When I add JSON to the gateway header, then I do stress testing, the thread cannot recovery; I used the top - H command in Linux system to monitor the number of threads increasing, and found that the growing number of threads could not be recovery

Leaked threads are mainly held by subordinate services

Sample

I found that when there is only one header JSON information, the problem will not occur. If you add another common header information, the problem will appear Complete code:

@Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        ServerHttpRequest request = exchange.getRequest();
        ServerHttpRequest.Builder builder = request.mutate();
        builder.header("user-info", "{ \"name\": \"BeJson\", \"url\": \"http://www.xxxxx.com\", \"page\": 88, \"isNonProfit\": true, \"address\": { \"street\": \"xxxx.\", \"city\": \"xxxx\", \"country\": \"xxxx\" } }");
        builder.header("depth-level", "1");
        return chain.filter(exchange.mutate().request(builder.build()).build());
    }

testThread

jipeigong commented 3 years ago

My subordinate service caused a thread leak, not gateway related